Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,13 @@ models = {
|
|
8 |
"BLIP": (AutoProcessor, BlipForQuestionAnswering, "Salesforce/blip-vqa-base"),
|
9 |
}
|
10 |
|
11 |
-
def get_format_response(selected_model
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
if selected_model=='ViLT':
|
13 |
logits = outputs.logits
|
14 |
idx = logits.argmax(-1).item()
|
@@ -25,11 +31,6 @@ st.subheader("A demo app showcasing VQA models. ViLT and BLIP model.")
|
|
25 |
# Sidebar for model selection
|
26 |
selected_model = st.sidebar.selectbox("Select Model", list(models.keys()))
|
27 |
|
28 |
-
# Load selected model and processor
|
29 |
-
processor, model_class, model_name = models[selected_model]
|
30 |
-
processor = processor.from_pretrained(model_name)
|
31 |
-
model = model_class.from_pretrained(model_name)
|
32 |
-
|
33 |
# Image and question input
|
34 |
uploaded_image = st.file_uploader("Upload Image")
|
35 |
question = st.text_input("Ask a Question about the Image")
|
@@ -38,9 +39,7 @@ question = st.text_input("Ask a Question about the Image")
|
|
38 |
if uploaded_image and question:
|
39 |
image = Image.open(uploaded_image)
|
40 |
st.image(image, caption="Uploaded Image")
|
41 |
-
|
42 |
-
outputs = model(**encoding)
|
43 |
-
answer = get_format_response(selected_model,outputs)
|
44 |
# Display answer
|
45 |
st.write(f"π€ Model Answer: {answer} π")
|
46 |
# Disclaimer
|
|
|
8 |
"BLIP": (AutoProcessor, BlipForQuestionAnswering, "Salesforce/blip-vqa-base"),
|
9 |
}
|
10 |
|
11 |
+
def get_format_response(image,question,selected_model):
|
12 |
+
# Load selected model and processor
|
13 |
+
processor, model_class, model_name = models[selected_model]
|
14 |
+
processor = processor.from_pretrained(model_name)
|
15 |
+
model = model_class.from_pretrained(model_name)
|
16 |
+
encoding = processor(image, question, return_tensors="pt")
|
17 |
+
outputs = model(**encoding)
|
18 |
if selected_model=='ViLT':
|
19 |
logits = outputs.logits
|
20 |
idx = logits.argmax(-1).item()
|
|
|
31 |
# Sidebar for model selection
|
32 |
selected_model = st.sidebar.selectbox("Select Model", list(models.keys()))
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
# Image and question input
|
35 |
uploaded_image = st.file_uploader("Upload Image")
|
36 |
question = st.text_input("Ask a Question about the Image")
|
|
|
39 |
if uploaded_image and question:
|
40 |
image = Image.open(uploaded_image)
|
41 |
st.image(image, caption="Uploaded Image")
|
42 |
+
answer = get_format_response(image,question,selected_model)
|
|
|
|
|
43 |
# Display answer
|
44 |
st.write(f"π€ Model Answer: {answer} π")
|
45 |
# Disclaimer
|