Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,17 @@ models = {
|
|
8 |
"BLIP": (AutoProcessor, BlipForQuestionAnswering, "Salesforce/blip-vqa-base"),
|
9 |
}
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# Streamlit app
|
12 |
st.title("Simple VQA App π€π")
|
13 |
st.subheader("A demo app showcasing VQA models. ViLT and BLIP model.")
|
@@ -29,10 +40,8 @@ if uploaded_image and question:
|
|
29 |
st.image(image, caption="Uploaded Image")
|
30 |
encoding = processor(image, question, return_tensors="pt")
|
31 |
outputs = model(**encoding)
|
32 |
-
|
33 |
-
|
34 |
-
answer = model.config.id2label[idx]
|
35 |
-
# Display answer with animation emoji
|
36 |
st.write(f"π€ Model Answer: {answer} π")
|
37 |
# Disclaimer
|
38 |
st.sidebar.markdown("This is a demo app showcasing VQA models. Actual performance may vary.")
|
|
|
8 |
"BLIP": (AutoProcessor, BlipForQuestionAnswering, "Salesforce/blip-vqa-base"),
|
9 |
}
|
10 |
|
11 |
+
def get_format_response(selected_model,outputs):
|
12 |
+
if selected_model=='ViLT':
|
13 |
+
logits = outputs.logits
|
14 |
+
idx = logits.argmax(-1).item()
|
15 |
+
answer = model.config.id2label[idx]
|
16 |
+
return answer
|
17 |
+
else:
|
18 |
+
answer = processor.decode(out[0], skip_special_tokens=True)
|
19 |
+
return answer
|
20 |
+
|
21 |
+
|
22 |
# Streamlit app
|
23 |
st.title("Simple VQA App π€π")
|
24 |
st.subheader("A demo app showcasing VQA models. ViLT and BLIP model.")
|
|
|
40 |
st.image(image, caption="Uploaded Image")
|
41 |
encoding = processor(image, question, return_tensors="pt")
|
42 |
outputs = model(**encoding)
|
43 |
+
answer = get_format_response(selected_model,outputs)
|
44 |
+
# Display answer
|
|
|
|
|
45 |
st.write(f"π€ Model Answer: {answer} π")
|
46 |
# Disclaimer
|
47 |
st.sidebar.markdown("This is a demo app showcasing VQA models. Actual performance may vary.")
|