m7mdal7aj commited on
Commit
bd86418
·
verified ·
1 Parent(s): 7a98a64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -20,11 +20,6 @@ def answer_question(caption, detected_objects_str, question, model):
20
  answer = model.generate_answer(question, caption, detected_objects_str)
21
  return answer
22
 
23
- def get_caption(image):
24
- return "Generated caption for the image"
25
-
26
- def free_gpu_resources():
27
- pass
28
 
29
  # Sample images (assuming these are paths to your sample images)
30
  sample_images = ["Files/sample1.jpg", "Files/sample2.jpg", "Files/sample3.jpg",
@@ -34,9 +29,12 @@ sample_images = ["Files/sample1.jpg", "Files/sample2.jpg", "Files/sample3.jpg",
34
 
35
 
36
  def analyze_image(image, model):
37
- st.write("Analyzing . . .")
38
  caption = model.get_caption(image)
39
  image_with_boxes, detected_objects_str = model.detect_objects(image)
 
 
 
40
  return caption, detected_objects_str
41
 
42
 
@@ -110,7 +108,7 @@ def run_inference():
110
  detection_model = st.selectbox(
111
  "Choose a model for object detection:",
112
  ["yolov5", "detic"],
113
- index=0
114
  )
115
 
116
  default_confidence = 0.2 if detection_model == "yolov5" else 0.4
@@ -135,14 +133,16 @@ def run_inference():
135
  st.session_state['kbvqa'] = None
136
 
137
  if st.button(button_label):
 
138
  if st.session_state['kbvqa'] is not None and not settings_changed:
139
  st.write("Model already loaded.")
140
  else:
141
- st.text("Loading the model will take no more than a few minutes . .")
142
  st.session_state['kbvqa'] = prepare_kbvqa_model(detection_model)
143
  st.session_state['kbvqa'].detection_confidence = confidence_level
144
  st.session_state['model_settings'] = {'detection_model': detection_model, 'confidence_level': confidence_level}
145
  st.write("Model is ready for inference.")
 
146
 
147
  if st.session_state['kbvqa']:
148
  image_qa_app(st.session_state['kbvqa'])
 
20
  answer = model.generate_answer(question, caption, detected_objects_str)
21
  return answer
22
 
 
 
 
 
 
23
 
24
  # Sample images (assuming these are paths to your sample images)
25
  sample_images = ["Files/sample1.jpg", "Files/sample2.jpg", "Files/sample3.jpg",
 
29
 
30
 
31
  def analyze_image(image, model):
32
+ st.text("Cool image, let me analyze it..")
33
  caption = model.get_caption(image)
34
  image_with_boxes, detected_objects_str = model.detect_objects(image)
35
+ st.text("I am ready, let's talk!")
36
+ free_gpu_resources()
37
+
38
  return caption, detected_objects_str
39
 
40
 
 
108
  detection_model = st.selectbox(
109
  "Choose a model for object detection:",
110
  ["yolov5", "detic"],
111
+ index=1 # "detic" is selected by default
112
  )
113
 
114
  default_confidence = 0.2 if detection_model == "yolov5" else 0.4
 
133
  st.session_state['kbvqa'] = None
134
 
135
  if st.button(button_label):
136
+ free_gpu_resources()
137
  if st.session_state['kbvqa'] is not None and not settings_changed:
138
  st.write("Model already loaded.")
139
  else:
140
+ st.text("Loading the model will take no more than a few minutes dpending on the hardware configuration . .")
141
  st.session_state['kbvqa'] = prepare_kbvqa_model(detection_model)
142
  st.session_state['kbvqa'].detection_confidence = confidence_level
143
  st.session_state['model_settings'] = {'detection_model': detection_model, 'confidence_level': confidence_level}
144
  st.write("Model is ready for inference.")
145
+ free_gpu_resources()
146
 
147
  if st.session_state['kbvqa']:
148
  image_qa_app(st.session_state['kbvqa'])