Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
-
from transformers import BlipForQuestionAnswering
|
|
|
|
|
|
|
|
|
2 |
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
|
3 |
processor = AutoProcessor.from_pretrained("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 |
-
image
|
|
|
|
|
10 |
inputs = processor(image, question, return_tensors="pt")
|
11 |
out = model.generate(**inputs)
|
12 |
answer = processor.decode(out[0], skip_special_tokens=True)
|
@@ -14,10 +17,15 @@ def answer_question(image, question):
|
|
14 |
|
15 |
# Create Gradio interface
|
16 |
image_input = gr.Image(label="Upload Image")
|
17 |
-
question_input = gr.Textbox(label="Ask a Question",lines
|
18 |
output = gr.Textbox(label="Answer")
|
19 |
|
20 |
-
interface = gr.Interface(
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
|
|
|
|
1 |
+
from transformers import BlipForQuestionAnswering, AutoProcessor
|
2 |
+
import gradio as gr
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
+
|
6 |
model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
|
7 |
processor = AutoProcessor.from_pretrained("Salesforce/blip-vqa-base")
|
|
|
|
|
|
|
8 |
|
9 |
def answer_question(image, question):
|
10 |
+
# Open the image file-like object
|
11 |
+
image = Image.open(io.BytesIO(image.read()))
|
12 |
+
|
13 |
inputs = processor(image, question, return_tensors="pt")
|
14 |
out = model.generate(**inputs)
|
15 |
answer = processor.decode(out[0], skip_special_tokens=True)
|
|
|
17 |
|
18 |
# Create Gradio interface
|
19 |
image_input = gr.Image(label="Upload Image")
|
20 |
+
question_input = gr.Textbox(label="Ask a Question", lines=4)
|
21 |
output = gr.Textbox(label="Answer")
|
22 |
|
23 |
+
interface = gr.Interface(
|
24 |
+
fn=answer_question,
|
25 |
+
inputs=[image_input, question_input],
|
26 |
+
outputs=output,
|
27 |
+
title="Multimodal Question Answering",
|
28 |
+
description="BlipForQuestionAnswering for Question Answering",
|
29 |
+
)
|
30 |
|
31 |
+
interface.launch()
|