roshithindia commited on
Commit
d32b633
·
1 Parent(s): ee4ba1a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import ViltProcessor, ViltForQuestionAnswering
2
+ from PIL import Image
3
+ import streamlit as st
4
+
5
+ x = st.file_uploader("Upload Images", type=["png","jpg","jpeg"])
6
+ if x is not None:
7
+ st.image(Image.open(x), width=250)
8
+ i = Image.open(x)
9
+ question = st.text_input("Enter your question about the image ?")
10
+ processor = ViltProcessor.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
11
+ model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
12
+ encoding = processor(i, question, return_tensors="pt")
13
+ outputs = model(**encoding)
14
+ logits = outputs.logits
15
+ idx = logits.argmax(-1).item()
16
+ st.write("Model replay:", model.config.id2label[idx])