m7mdal7aj commited on
Commit
f960a9d
·
verified ·
1 Parent(s): 4c78312

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
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
- question = st.text_input(f"Ask a question about this image ({image_key}):", key=f'question_{image_key}')
74
- if st.button('Get Answer', key=f'answer_{image_key}'):
75
- answer = answer_question(image_data['caption'], image_data['detected_objects_str'], question, kbvqa)
76
- image_data['qa_history'].append((question, answer))
77
-
78
- for q, a in image_data['qa_history']:
79
- st.text(f"Q: {q}\nA: {a}\n")
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", "Evaluation Results", "Finetuning and Evaluation Results", "Run Inference", "Dissertation Report"])
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":