File size: 1,061 Bytes
f15b4fe
 
9bc25a6
 
 
 
887ecc1
7db4531
887ecc1
9bc25a6
887ecc1
f15b4fe
3f8e55d
 
12ab3b2
18d19c8
12ab3b2
7db4531
887ecc1
7db4531
9bc25a6
 
02cdfb8
9bc25a6
 
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
import streamlit as st
from PIL import Image
# Initialize session state to block re-running
if 'has_run' not in st.session_state:
    st.session_state.has_run = False

# Main UI container
st.markdown('<h3><center><b>VQA</b></center></h3>', unsafe_allow_html=True)
# Image upload area
uploaded_image = st.sidebar.file_uploader("Upload your image here", type=["jpg", "jpeg", "png"])
# Display the uploaded image and process it if available
if uploaded_image is not None:
    image = Image.open(uploaded_image)
    st.image(image, caption="Uploaded Image", use_column_width=True)
    # Task prompt input
    task_prompt = st.sidebar.text_input("Task Prompt", value="Describe the image in detail:")
    # Additional text input (optional)
    text_input = st.sidebar.text_area("Input Questions", height=20)
    # Generate Caption button
    if st.sidebar.button("Generate Caption", key="Generate") and not st.session_state.has_run:
        # Mark that the script has been run
        st.session_state.has_run = True
        st.write(task_prompt,"\n\n",text_input)