File size: 1,040 Bytes
92db232 5cab462 92db232 43f28ea 92db232 33dd3de 92db232 33dd3de 92db232 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from PIL import Image
import requests
from io import BytesIO
from transformers import pipeline
import streamlit as st
def predict(image):
type_food = oracle(image, "What type of food is this?")
cal_est = oracle(image, "About how many calories are in this meal?")
guess1, guess2 = int(cal_est[0]['answer']), int(cal_est[1]['answer'])
return f"This is {type_food[0]['answer']}. I estimate this to contain {min(guess1, guess2)}-{max(guess1, guess2)} calories"
oracle = pipeline(model="dandelin/vilt-b32-finetuned-vqa")
def main():
st.title("Image Question Answering App")
st.write("Upload an image and ask a question to get answers!")
# File uploader for image
uploaded_image = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
if uploaded_image is not None:
image = Image.open(uploaded_image)
st.image(image, caption="Uploaded Image", use_column_width=True)
response = predict(image)
st.write(response)
if __name__ == "__main__":
main()
|