captain-awesome commited on
Commit
1a838e7
·
verified ·
1 Parent(s): 4bacce2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers.utils import logging
3
+ logging.set_verbosity_error()
4
+
5
+ import warnings
6
+ warnings.filterwarnings("ignore", message="Using the model-agnostic default `max_length`")
7
+
8
+ from transformers import BlipForQuestionAnswering
9
+ from transformers import AutoProcessor
10
+
11
+ def qa(inputs):
12
+ model = BlipForQuestionAnswering.from_pretrained(
13
+ "./models/Salesforce/blip-vqa-base")
14
+ processor = AutoProcessor.from_pretrained(
15
+ "./models/Salesforce/blip-vqa-base")
16
+ inputs = processor(image, question, return_tensors="pt")
17
+
18
+ out = model.generate(**inputs)
19
+
20
+ return processor.decode(out[0], skip_special_tokens=True)
21
+
22
+ # def greet(name):
23
+ # return "Hello " + name + "!!"
24
+
25
+ iface = gr.Interface(fn=qa, inputs=["image","text"], outputs="text")
26
+ iface.launch()