Update app.py
Browse files
app.py
CHANGED
@@ -73,26 +73,32 @@ def image_qa_app(kbvqa):
|
|
73 |
# Image uploader
|
74 |
uploaded_image = st.file_uploader("Or upload an Image", type=["png", "jpg", "jpeg"])
|
75 |
if uploaded_image is not None:
|
76 |
-
|
|
|
|
|
77 |
st.session_state['qa_history'] = []
|
78 |
|
79 |
-
# Display the current image
|
80 |
-
if st.session_state
|
81 |
st.image(st.session_state['current_image'], caption='Uploaded Image.', use_column_width=True)
|
82 |
|
83 |
-
# Question input
|
84 |
question = st.text_input("Ask a question about this image:")
|
85 |
-
|
86 |
-
# Get Answer button
|
87 |
if st.button('Get Answer'):
|
88 |
-
#
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
|
98 |
# Main function
|
|
|
73 |
# Image uploader
|
74 |
uploaded_image = st.file_uploader("Or upload an Image", type=["png", "jpg", "jpeg"])
|
75 |
if uploaded_image is not None:
|
76 |
+
image = Image.open(uploaded_image)
|
77 |
+
st.session_state['current_image'] = image
|
78 |
+
st.session_state['processed_image'] = copy.deepcopy(image) # Create a copy for processing
|
79 |
st.session_state['qa_history'] = []
|
80 |
|
81 |
+
# Display the current image (unaltered)
|
82 |
+
if st.session_state.get('current_image') is not None:
|
83 |
st.image(st.session_state['current_image'], caption='Uploaded Image.', use_column_width=True)
|
84 |
|
85 |
+
# Question input and processing
|
86 |
question = st.text_input("Ask a question about this image:")
|
|
|
|
|
87 |
if st.button('Get Answer'):
|
88 |
+
# Use the processed image for object detection and other processing
|
89 |
+
processed_image = st.session_state.get('processed_image')
|
90 |
+
if processed_image:
|
91 |
+
# Perform object detection or other processing on processed_image
|
92 |
+
# For example: processed_image = perform_object_detection(processed_image)
|
93 |
+
answer = answer_question(processed_image, question, model=kbvqa)
|
94 |
+
st.session_state['qa_history'].append((question, answer))
|
95 |
+
|
96 |
+
# Display all Q&A
|
97 |
+
for q, a in st.session_state['qa_history']:
|
98 |
+
st.text(f"Q: {q}\nA: {a}\n")
|
99 |
+
|
100 |
+
# Update the processed image in session state
|
101 |
+
st.session_state['processed_image'] = processed_image
|
102 |
|
103 |
|
104 |
# Main function
|