m7mdal7aj commited on
Commit
2d605ad
1 Parent(s): 682bc75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -13,9 +13,13 @@ from my_model.KBVQA import KBVQA, prepare_kbvqa_model
13
 
14
 
15
 
16
- def answer_question(image, question, model):
17
 
18
- answer = model.generate_answer(question, image)
 
 
 
 
19
  return answer
20
 
21
  def get_caption(image):
@@ -31,14 +35,13 @@ sample_images = ["Files/sample1.jpg", "Files/sample2.jpg", "Files/sample3.jpg",
31
 
32
 
33
 
34
- def analyze_image(image, model):
35
- # Placeholder for your analysis function
36
- # This function should prepare captions, detect objects, etc.
37
- # For example:
38
- # caption = model.get_caption(image)
39
- # detected_objects = model.detect_objects(image)
40
- # return caption, detected_objects
41
- pass
42
 
43
  def image_qa_app(kbvqa):
44
  # Initialize session state for storing the current image and its Q&A history
@@ -77,7 +80,7 @@ def image_qa_app(kbvqa):
77
  if st.session_state.get('current_image') and not st.session_state['analysis_done']:
78
  if st.button('Analyze Image'):
79
  # Perform analysis on the image
80
- analyze_image(st.session_state['current_image'], kbvqa)
81
  st.session_state['analysis_done'] = True
82
  st.session_state['processed_image'] = copy.deepcopy(st.session_state['current_image'])
83
 
@@ -90,7 +93,7 @@ def image_qa_app(kbvqa):
90
  question = st.text_input("Ask a question about this image:")
91
  if st.button('Get Answer'):
92
  st.session_state['answer_in_progress'] = True
93
- answer = answer_question(st.session_state['processed_image'], question, model=kbvqa)
94
  st.session_state['qa_history'].append((question, answer))
95
 
96
 
@@ -153,7 +156,7 @@ def run_inference():
153
  # Main function
154
  def main():
155
  st.sidebar.title("Navigation")
156
- selection = st.sidebar.radio("Go to", ["Home", "Dataset Analysis", "Evaluation Results", "Run Inference", "Dissertation Report", "Object Detection"])
157
 
158
  if selection == "Home":
159
  st.title("MultiModal Learning for Knowledg-Based Visual Question Answering")
 
13
 
14
 
15
 
16
+ def answer_question(image, question, caption, detected_objects_str, model):
17
 
18
+ answer = model.generate_answer(question, image, caption, detected_objects_str)
19
+ st.image(image)
20
+ st.write(caption)
21
+ st.write("----------------")
22
+ st.write(detected_objects_str)
23
  return answer
24
 
25
  def get_caption(image):
 
35
 
36
 
37
 
38
+ def analyze_image(image, model, show_processed_image=False):
39
+ img = copy.deepcopy(image)
40
+ caption = model.get_caption(img)
41
+ image_with_boxes, detected_objects_str = model.detect_objects(img)
42
+ if show_processed_image:
43
+ st.image(image_with_boxes)
44
+ return caption, detected_objects
 
45
 
46
  def image_qa_app(kbvqa):
47
  # Initialize session state for storing the current image and its Q&A history
 
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 = 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
 
 
93
  question = st.text_input("Ask a question about this image:")
94
  if st.button('Get Answer'):
95
  st.session_state['answer_in_progress'] = True
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
 
 
156
  # Main function
157
  def main():
158
  st.sidebar.title("Navigation")
159
+ selection = st.sidebar.radio("Go to", ["Home", "Dataset Analysis", "Evaluation Results", "Run Inference", "Dissertation Report"])
160
 
161
  if selection == "Home":
162
  st.title("MultiModal Learning for Knowledg-Based Visual Question Answering")