Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,4 +14,29 @@ question = "What does the label 15 represent? (1) lava (2) core (3) tunnel (4) a
|
|
| 14 |
inputs = processor(images=image, text=question, return_tensors="pt")
|
| 15 |
|
| 16 |
predictions = model.generate(**inputs)
|
| 17 |
-
print(processor.decode(predictions[0], skip_special_tokens=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
inputs = processor(images=image, text=question, return_tensors="pt")
|
| 15 |
|
| 16 |
predictions = model.generate(**inputs)
|
| 17 |
+
# print(processor.decode(predictions[0], skip_special_tokens=True))
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def load_image():
|
| 22 |
+
with st.sidebar:
|
| 23 |
+
if img := st.text_input("Enter Image URL") or st.selectbox("Select Image", ("https://images.unsplash.com/photo-1593466144596-8abd50ad2c52?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3434&q=80", "https://images.unsplash.com/photo-1566438480900-0609be27a4be?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3394&q=80")):
|
| 24 |
+
if st.button("Load Image"):
|
| 25 |
+
st.write("Image Uploaded!")
|
| 26 |
+
st.image(img)
|
| 27 |
+
else:
|
| 28 |
+
st.warning("Please enter an image URL and click 'Load Image' before asking a question.")
|
| 29 |
+
return img
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def visual_qna():
|
| 34 |
+
st.title("Visual Q&A")
|
| 35 |
+
img = load_image()
|
| 36 |
+
if img:
|
| 37 |
+
if query := st.chat_input("Enter your message"):
|
| 38 |
+
response = model(question=query, image=img)
|
| 39 |
+
with st.chat_message("assistant"):
|
| 40 |
+
st.write(response)
|
| 41 |
+
else:
|
| 42 |
+
st.warning("Please enter an image URL and click 'Load Image' before asking a question.")
|