Update app.py
Browse files
app.py
CHANGED
|
@@ -2,24 +2,22 @@ import streamlit as st
|
|
| 2 |
from PIL import Image
|
| 3 |
import requests
|
| 4 |
from io import BytesIO
|
| 5 |
-
|
| 6 |
-
# Function to perform image question answering
|
| 7 |
-
def perform_image_qa(image, question):
|
| 8 |
-
inputs = {"image": image, "question": question}
|
| 9 |
-
response = hf_spaces.use_model(model_name, inputs)
|
| 10 |
-
return response['answer']
|
| 11 |
|
| 12 |
def main():
|
| 13 |
st.title("Image Question Answering App")
|
| 14 |
st.write("Upload an image and ask a question to get answers!")
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
# File uploader for image
|
| 17 |
uploaded_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
| 18 |
-
|
| 19 |
if uploaded_image is not None:
|
| 20 |
image = Image.open(uploaded_image)
|
| 21 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 22 |
-
|
|
|
|
| 23 |
# # Ask question
|
| 24 |
# question = st.text_input("Ask your question here:")
|
| 25 |
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
import requests
|
| 4 |
from io import BytesIO
|
| 5 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def main():
|
| 8 |
st.title("Image Question Answering App")
|
| 9 |
st.write("Upload an image and ask a question to get answers!")
|
| 10 |
+
|
| 11 |
+
oracle = pipeline(model="dandelin/vilt-b32-finetuned-vqa")
|
| 12 |
+
|
| 13 |
# File uploader for image
|
| 14 |
uploaded_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
| 15 |
+
|
| 16 |
if uploaded_image is not None:
|
| 17 |
image = Image.open(uploaded_image)
|
| 18 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 19 |
+
response = oracle(image, "What kind of food is this?")
|
| 20 |
+
st.write(f"{response}")
|
| 21 |
# # Ask question
|
| 22 |
# question = st.text_input("Ask your question here:")
|
| 23 |
|