m7mdal7aj commited on
Commit
2b41e89
·
verified ·
1 Parent(s): a4d2f44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -121,7 +121,7 @@ def run_inference():
121
  )
122
 
123
  if 'model_settings' not in st.session_state:
124
- st.session_state['model_settings'] = {'detection_model': None, 'confidence_level': None}
125
 
126
  settings_changed = (st.session_state['model_settings']['detection_model'] != detection_model or
127
  st.session_state['model_settings']['confidence_level'] != confidence_level)
@@ -133,9 +133,18 @@ def run_inference():
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 . .")
141
  st.session_state['kbvqa'] = prepare_kbvqa_model(detection_model)
@@ -144,6 +153,8 @@ def run_inference():
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'])
149
 
@@ -191,6 +202,7 @@ def main():
191
 
192
 
193
  elif selection == "Run Inference":
 
194
  run_inference()
195
 
196
  elif selection == "Code":
 
121
  )
122
 
123
  if 'model_settings' not in st.session_state:
124
+ st.session_state['model_settings'] = {'detection_model': detection_model, 'confidence_level': confidence_level}
125
 
126
  settings_changed = (st.session_state['model_settings']['detection_model'] != detection_model or
127
  st.session_state['model_settings']['confidence_level'] != confidence_level)
 
133
  st.session_state['kbvqa'] = None
134
 
135
  if st.button(button_label):
136
+
137
  free_gpu_resources()
138
+ if st.session_state['kbvqa'] is not None:
139
+ if not settings_changed:
140
+ st.write("Model already loaded.")
141
+ else:
142
+ free_gpu_resources()
143
+ detection_model = st.session_state['model_settings']['detection_model']
144
+ confidence_level = st.session_state['model_settings']['confidence_level']
145
+ prepare_kbvqa_model(detection_model, only_reload_detection_model=True) # only reload detection model with new settings
146
+ st.session_state['kbvqa'].detection_confidence = confidence_level
147
+ free_gpu_resources()
148
  else:
149
  st.text("Loading the model will take no more than a few minutes . .")
150
  st.session_state['kbvqa'] = prepare_kbvqa_model(detection_model)
 
153
  st.write("Model is ready for inference.")
154
  free_gpu_resources()
155
 
156
+
157
+
158
  if st.session_state['kbvqa']:
159
  image_qa_app(st.session_state['kbvqa'])
160
 
 
202
 
203
 
204
  elif selection == "Run Inference":
205
+ st.text("Please note that this is not a general purpose model, it is specifically trained on OK-VQA dataset and is designed to give short answers to the given questions.")
206
  run_inference()
207
 
208
  elif selection == "Code":