m7mdal7aj commited on
Commit
b749133
1 Parent(s): db44281

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -15,9 +15,9 @@ from my_model.KBVQA import KBVQA, prepare_kbvqa_model
15
 
16
 
17
 
18
- def answer_question(image, question, model):
19
 
20
- answer = model.generate_answer(question, image)
21
  return answer
22
 
23
  def get_caption(image):
@@ -37,10 +37,10 @@ def analyze_image(image, model):
37
  # Placeholder for your analysis function
38
  # This function should prepare captions, detect objects, etc.
39
  # For example:
40
- # caption = model.get_caption(image)
41
- # detected_objects = model.detect_objects(image)
42
- # return caption, detected_objects
43
- pass
44
 
45
  def image_qa_app(kbvqa):
46
  # Initialize session state for storing the current image and its Q&A history.
@@ -85,7 +85,7 @@ def image_qa_app(kbvqa):
85
  if st.session_state.get('current_image') and not st.session_state['analysis_done']:
86
  if st.button('Analyze Image'):
87
  # Perform analysis on the image
88
- analyze_image(st.session_state['current_image'], kbvqa)
89
  st.session_state['analysis_done'] = True
90
  st.session_state['processed_image'] = copy.deepcopy(st.session_state['current_image'])
91
 
@@ -94,7 +94,7 @@ def image_qa_app(kbvqa):
94
  question = st.text_input("Ask a question about this image:")
95
  if st.button('Get Answer'):
96
  st.session_state['answer_in_progress'] = True
97
- answer = answer_question(st.session_state['processed_image'], question, model=kbvqa)
98
  st.session_state['qa_history'].append((question, answer))
99
 
100
  # Display all Q&A
 
15
 
16
 
17
 
18
+ def answer_question(caption, detected_objects_str, question, model=kbvqa):
19
 
20
+ answer = model.generate_answer(question, caption, detected_objects_str)
21
  return answer
22
 
23
  def get_caption(image):
 
37
  # Placeholder for your analysis function
38
  # This function should prepare captions, detect objects, etc.
39
  # For example:
40
+ caption = model.get_caption(image)
41
+ image_with_boxes, detected_objects_str = model.detect_objects(image)
42
+ return caption, detected_objects_str
43
+
44
 
45
  def image_qa_app(kbvqa):
46
  # Initialize session state for storing the current image and its Q&A history.
 
85
  if st.session_state.get('current_image') and not st.session_state['analysis_done']:
86
  if st.button('Analyze Image'):
87
  # Perform analysis on the image
88
+ caption, detected_objects_str = analyze_image(st.session_state['current_image'], kbvqa)
89
  st.session_state['analysis_done'] = True
90
  st.session_state['processed_image'] = copy.deepcopy(st.session_state['current_image'])
91
 
 
94
  question = st.text_input("Ask a question about this image:")
95
  if st.button('Get Answer'):
96
  st.session_state['answer_in_progress'] = True
97
+ answer = answer_question(caption, detected_objects_str, question, model=kbvqa)
98
  st.session_state['qa_history'].append((question, answer))
99
 
100
  # Display all Q&A