Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
gr.Interface.load("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# gr.Interface.load("prasanna2003/blip-image-captioning").launch()
|
4 |
+
|
5 |
+
from PIL import Image
|
6 |
+
import requests
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
10 |
+
|
11 |
+
model_id = "prasanna2003/blip-image-captioning"
|
12 |
+
|
13 |
+
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
14 |
+
processor = BlipProcessor.from_pretrained(model_id)
|
15 |
+
|
16 |
+
def launch(input):
|
17 |
+
image = Image.open(requests.get(input, stream=True).raw).convert('RGB')
|
18 |
+
inputs = processor(image, return_tensors="pt")
|
19 |
+
out = model.generate(**inputs)
|
20 |
+
return processor.decode(out[0], skip_special_tokens=True)
|
21 |
+
|
22 |
+
iface = gr.Interface(launch, inputs="text", outputs="text")
|
23 |
+
iface.launch()
|