Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -76,30 +76,23 @@ def image_qa_app(kbvqa):
|
|
76 |
st.session_state['analysis_done'] = False
|
77 |
st.session_state['answer_in_progress'] = False
|
78 |
|
79 |
-
|
80 |
-
if st.session_state.get('current_image') and not st.session_state['analysis_done']:
|
81 |
if st.button('Analyze Image'):
|
82 |
-
# Perform analysis on the image
|
83 |
caption, detected_objects_str = analyze_image(st.session_state['current_image'], kbvqa)
|
|
|
|
|
84 |
st.session_state['analysis_done'] = True
|
85 |
-
st.session_state['processed_image'] = copy.deepcopy(st.session_state['current_image'])
|
86 |
-
|
87 |
-
# Display the current image (unaltered)
|
88 |
-
if st.session_state.get('current_image'):
|
89 |
-
st.image(st.session_state['current_image'], caption='Uploaded Image.', use_column_width=True)
|
90 |
|
91 |
# Get Answer button
|
92 |
-
if st.session_state
|
93 |
question = st.text_input("Ask a question about this image:")
|
94 |
if st.button('Get Answer'):
|
95 |
-
st.session_state['
|
96 |
-
answer = answer_question(st.session_state['processed_image'], question, caption, detected_objects_str, model=kbvqa)
|
97 |
st.session_state['qa_history'].append((question, answer))
|
98 |
-
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
|
104 |
# Reset the answer_in_progress flag after displaying the answer
|
105 |
if st.session_state['answer_in_progress']:
|
|
|
76 |
st.session_state['analysis_done'] = False
|
77 |
st.session_state['answer_in_progress'] = False
|
78 |
|
79 |
+
if st.session_state.get('current_image') and not st.session_state.get('analysis_done', False):
|
|
|
80 |
if st.button('Analyze Image'):
|
|
|
81 |
caption, detected_objects_str = analyze_image(st.session_state['current_image'], kbvqa)
|
82 |
+
st.session_state['caption'] = caption
|
83 |
+
st.session_state['detected_objects_str'] = detected_objects_str
|
84 |
st.session_state['analysis_done'] = True
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
# Get Answer button
|
87 |
+
if st.session_state.get('analysis_done', False):
|
88 |
question = st.text_input("Ask a question about this image:")
|
89 |
if st.button('Get Answer'):
|
90 |
+
answer = answer_question(st.session_state['current_image'], question, st.session_state.get('caption', ''), st.session_state.get('detected_objects_str', ''), kbvqa)
|
|
|
91 |
st.session_state['qa_history'].append((question, answer))
|
|
|
92 |
|
93 |
+
# Display all Q&A
|
94 |
+
for q, a in st.session_state.get('qa_history', []):
|
95 |
+
st.text(f"Q: {q}\nA: {a}\n")
|
96 |
|
97 |
# Reset the answer_in_progress flag after displaying the answer
|
98 |
if st.session_state['answer_in_progress']:
|