Upload 2 files
Browse files
Readme
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This is demo to use Visual question answering model using E2Ecloud ML.
|
2 |
+
This is based on gradio UI app with Azure cloud backend
|
3 |
+
Azure components used are storage,database,VM,CDN , load balancer.
|
4 |
+
Webserver is run Azure VM.
|
5 |
+
User can load images from client , that is stored in Azure backendand used by processos to access and process.
|
6 |
+
The processing transformer VQA module ( dandelin/vilt-b32-finetuned-vqa ) is loaded from huggingface interface.
|
7 |
+
|
8 |
+
The cloud backend is used for scaling
|
vqa.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import ViltProcessor, ViltForQuestionAnswering
|
4 |
+
|
5 |
+
|
6 |
+
def getResult(query, image):
|
7 |
+
# prepare image + question
|
8 |
+
#image = Image.open(BytesIO(base64.b64decode(base64_encoded_image)))
|
9 |
+
text = query
|
10 |
+
|
11 |
+
processor = ViltProcessor.from_pretrained(
|
12 |
+
"dandelin/vilt-b32-finetuned-vqa")
|
13 |
+
model = ViltForQuestionAnswering.from_pretrained(
|
14 |
+
"dandelin/vilt-b32-finetuned-vqa")
|
15 |
+
|
16 |
+
# prepare inputs
|
17 |
+
encoding = processor(image, text, return_tensors="pt")
|
18 |
+
|
19 |
+
# forward pass
|
20 |
+
outputs = model(**encoding)
|
21 |
+
logits = outputs.logits
|
22 |
+
idx = logits.argmax(-1).item()
|
23 |
+
print("Predicted answer:", model.config.id2label[idx])
|
24 |
+
return model.config.id2label[idx]
|
25 |
+
|
26 |
+
|
27 |
+
iface = gr.Interface(fn=getResult, inputs=[
|
28 |
+
"text", gr.Image(type="pil")], outputs="text")
|
29 |
+
iface.launch(server_name="0.0.0.0",share=True)
|