refactor: app
Browse files
app.py
CHANGED
@@ -1,25 +1,28 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
-
from transformers import AutoProcessor, LlavaForConditionalGeneration
|
5 |
|
6 |
-
|
|
|
7 |
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
24 |
|
25 |
-
|
|
|
1 |
+
from PIL import Image
|
2 |
import gradio as gr
|
3 |
+
import requests
|
4 |
+
from transformers import AutoProcessor, BlipForQuestionAnswering
|
|
|
5 |
|
6 |
+
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
|
7 |
+
processor = AutoProcessor.from_pretrained("Salesforce/blip-vqa-base")
|
8 |
|
9 |
+
def generate_answer(text, image):
|
10 |
|
11 |
+
text = text
|
12 |
+
inputs = processor(images=image, text=text, return_tensors="pt")
|
13 |
+
outputs = model.generate(**inputs)
|
14 |
+
|
15 |
+
return processor.decode(outputs[0], skip_special_tokens=True)
|
16 |
|
17 |
+
text_input = gr.Textbox(lines=5, label="Enter text")
|
18 |
+
image_input = gr.Image(type="pil", label="Upload Image")
|
19 |
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=generate_answer,
|
22 |
+
inputs=[text_input, image_input],
|
23 |
+
outputs="text",
|
24 |
+
title="DD360-Bot-Multimodal",
|
25 |
+
description="Enter text and upload an image"
|
26 |
+
)
|
27 |
|
28 |
+
iface.launch()
|