m7mdal7aj commited on
Commit
6ea46e7
·
verified ·
1 Parent(s): e9a6c39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -23
app.py CHANGED
@@ -70,34 +70,21 @@ def image_qa_app(kbvqa):
70
  image_data['analysis_done'] = True
71
 
72
  if image_data['analysis_done']:
73
- # Initialize qa_history
74
- qa_history = []
75
-
76
- # Check if the question has already been asked
77
- current_image_key = st.session_state.get('current_image_key')
78
- question = st.text_input("Ask a question about this image:")
79
- if st.button('Get Answer'):
80
- # Ensure that the image data exists in the session state
81
- if current_image_key not in st.session_state['images_data']:
82
- st.session_state['images_data'][current_image_key] = {'qa_history': []}
83
-
84
- qa_history = st.session_state['images_data'][current_image_key].get('qa_history', [])
85
  if question not in [q for q, _ in qa_history]:
86
- # Assuming caption and detected_objects_str are already set
87
- caption = st.session_state.get('caption', '')
88
- detected_objects_str = st.session_state.get('detected_objects_str', '')
89
- answer = answer_question(caption, detected_objects_str, question, kbvqa)
90
  qa_history.append((question, answer))
91
- st.session_state['images_data'][current_image_key]['qa_history'] = qa_history
92
  else:
93
  st.info("This question has already been asked.")
94
 
95
- # Display Q&A history
96
- for q, a in qa_history:
97
- st.text(f"Q: {q}\nA: {a}\n")
98
- # Display Q&A history
99
- for q, a in qa_history:
100
- st.text(f"Q: {q}\nA: {a}\n")
101
  def process_new_image(image_key, image, kbvqa):
102
  """Process a new image and update the session state."""
103
  if image_key not in st.session_state['images_data']:
 
70
  image_data['analysis_done'] = True
71
 
72
  if image_data['analysis_done']:
73
+ question = st.text_input("Ask a question about this image:", key=f'question_{image_key}')
74
+ if st.button('Get Answer', key=f'answer_{image_key}'):
75
+ qa_history = image_data.get('qa_history', [])
 
 
 
 
 
 
 
 
 
76
  if question not in [q for q, _ in qa_history]:
77
+ answer = answer_question(image_data['caption'], image_data['detected_objects_str'], question, kbvqa)
 
 
 
78
  qa_history.append((question, answer))
79
+ image_data['qa_history'] = qa_history
80
  else:
81
  st.info("This question has already been asked.")
82
 
83
+ # Display Q&A history
84
+ for q, a in qa_history:
85
+ st.text(f"Q: {q}\nA: {a}\n")
86
+
87
+
 
88
  def process_new_image(image_key, image, kbvqa):
89
  """Process a new image and update the session state."""
90
  if image_key not in st.session_state['images_data']: