mixklim commited on
Commit
37e1eef
·
verified ·
1 Parent(s): e8b6d0a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ from transformers import AutoProcessor, BlipForQuestionAnswering
6
+
7
+ processor = AutoProcessor.from_pretrained(
8
+ "Salesforce/blip-vqa-base")
9
+
10
+ model = BlipForQuestionAnswering.from_pretrained(
11
+ "Salesforce/blip-vqa-base")
12
+
13
+ def launch(pil_image, question):
14
+ inputs = processor(pil_image, question, return_tensors="pt")
15
+ out = model.generate(**inputs)
16
+ return processor.decode(out[0], skip_special_tokens=True)
17
+
18
+ iface = gr.Interface(launch,
19
+ inputs=[gr.Image(label="Input image", type='pil'),
20
+ gr.Textbox(label="Question", lines=3)],
21
+ outputs=gr.Textbox(label="Answer", lines=3))
22
+
23
+ iface.launch()