Spaces:
Runtime error
Runtime error
create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import BlipForQuestionAnswering
|
2 |
+
model = BlipForQuestionAnswering.from_pretrained(
|
3 |
+
"Salesforce/blip-vqa-base")
|
4 |
+
from transformers import AutoProcessor
|
5 |
+
from PIL import Image
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
def answer_question(image, question):
|
9 |
+
inputs = processor(image, question, return_tensors="pt")
|
10 |
+
out = model.generate(**inputs)
|
11 |
+
answer = processor.decode(out[0], skip_special_tokens=True)
|
12 |
+
return answer
|
13 |
+
|
14 |
+
# Create Gradio interface
|
15 |
+
image_input = gr.Image(label="Upload Image")
|
16 |
+
question_input = gr.Textbox(label="Ask a Question")
|
17 |
+
output = gr.Textbox(label="Answer")
|
18 |
+
|
19 |
+
interface = gr.Interface(fn=answer_question, inputs=[image_input, question_input], outputs=output, title="Multimodal Question Answering")
|
20 |
+
|
21 |
+
interface.launch()
|
22 |
+
|