sanikamal commited on
Commit
eb86d7b
β€’
1 Parent(s): d52c0fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
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
- logits = outputs.logits
33
- idx = logits.argmax(-1).item()
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.")