Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,14 +70,28 @@ def image_qa_app(kbvqa):
|
|
| 70 |
image_data['analysis_done'] = True
|
| 71 |
|
| 72 |
if image_data['analysis_done']:
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
def process_new_image(image_key, image, kbvqa):
|
| 82 |
"""Process a new image and update the session state."""
|
| 83 |
if image_key not in st.session_state['images_data']:
|
|
@@ -140,7 +154,7 @@ def main():
|
|
| 140 |
|
| 141 |
|
| 142 |
st.sidebar.title("Navigation")
|
| 143 |
-
selection = st.sidebar.radio("Go to", ["Home", "Dataset Analysis", "
|
| 144 |
st.sidebar.write("More Pages will follow .. ")
|
| 145 |
|
| 146 |
if selection == "Home":
|
|
|
|
| 70 |
image_data['analysis_done'] = True
|
| 71 |
|
| 72 |
if image_data['analysis_done']:
|
| 73 |
+
# Check if the question has already been asked
|
| 74 |
+
current_image_key = st.session_state.get('current_image_key')
|
| 75 |
+
question = st.text_input("Ask a question about this image:")
|
| 76 |
+
if st.button('Get Answer'):
|
| 77 |
+
# Ensure that the image data exists in the session state
|
| 78 |
+
if current_image_key not in st.session_state['images_data']:
|
| 79 |
+
st.session_state['images_data'][current_image_key] = {'qa_history': []}
|
| 80 |
+
|
| 81 |
+
qa_history = st.session_state['images_data'][current_image_key].get('qa_history', [])
|
| 82 |
+
if question not in [q for q, _ in qa_history]:
|
| 83 |
+
# Assuming caption and detected_objects_str are already set
|
| 84 |
+
caption = st.session_state.get('caption', '')
|
| 85 |
+
detected_objects_str = st.session_state.get('detected_objects_str', '')
|
| 86 |
+
answer = answer_question(caption, detected_objects_str, question, kbvqa)
|
| 87 |
+
qa_history.append((question, answer))
|
| 88 |
+
st.session_state['images_data'][current_image_key]['qa_history'] = qa_history
|
| 89 |
+
else:
|
| 90 |
+
st.info("This question has already been asked.")
|
| 91 |
+
|
| 92 |
+
# Display Q&A history
|
| 93 |
+
for q, a in qa_history:
|
| 94 |
+
st.text(f"Q: {q}\nA: {a}\n")
|
| 95 |
def process_new_image(image_key, image, kbvqa):
|
| 96 |
"""Process a new image and update the session state."""
|
| 97 |
if image_key not in st.session_state['images_data']:
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
st.sidebar.title("Navigation")
|
| 157 |
+
selection = st.sidebar.radio("Go to", ["Home", "Dataset Analysis", "Finetuning and Evaluation Results", "Run Inference", "Dissertation Report"])
|
| 158 |
st.sidebar.write("More Pages will follow .. ")
|
| 159 |
|
| 160 |
if selection == "Home":
|