Spaces:
Sleeping
Sleeping
File size: 1,568 Bytes
ce172f3 e2bff68 ce172f3 a13c564 e218ea8 a13c564 a176e88 dc8e949 a911560 a176e88 |
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 30 31 32 33 34 35 36 37 38 39 |
import streamlit as st
from streamlit_option_menu import option_menu
from transformers import pipeline, Conversation
visualqna = pipeline(model="dandelin/vilt-b32-finetuned-vqa")
def load_image():
with st.sidebar:
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")):
if st.button("Load Image"):
st.write("Image Uploaded!")
st.image(img)
else:
st.warning("Please enter an image URL and click 'Load Image' before asking a question.")
return img
def visual_qna():
st.title("Visual Q&A")
img = load_image()
if img:
if query := st.chat_input("Enter your message"):
response = visualqna(question=query, image=img)
with st.chat_message("assistant"):
st.write(response)
else:
st.warning("Please enter an image URL and click 'Load Image' before asking a question.")
def dashboard():
st.title("Dashboard")
with st.sidebar:
selected = option_menu(None, [ "Visual Q&A" , "Logout"])
if selected == 'Visual Q&A':
visual_qna()
elif selected == 'Logout':
st.session_state.user = "visitor"
st.experimental_rerun() |