m7mdal7aj commited on
Commit
849e3ce
·
verified ·
1 Parent(s): 7ea3839

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -23
app.py CHANGED
@@ -92,29 +92,18 @@ def process_new_image(image_key, image, kbvqa):
92
  def run_inference():
93
  st.title("Run Inference")
94
 
95
- method = st.selectbox(
96
- "Choose a method:",
97
- ["Fine-Tuned Model", "In-Context Learning (n-shots)"],
98
- index=0 # Default to the first option
99
- )
100
-
101
- detection_model = st.selectbox(
102
- "Choose a model for object detection:",
103
- ["yolov5", "detic"],
104
- index=0 # Default to the first option
105
- )
106
-
107
- # Set default confidence based on the selected model
108
- default_confidence = 0.2 if detection_model == "yolov5" else 0.4
109
-
110
- # Slider for confidence level
111
- confidence_level = st.slider(
112
- "Select minimum detection confidence level",
113
- min_value=0.1,
114
- max_value=0.9,
115
- value=default_confidence,
116
- step=0.1
117
- )
118
 
119
 
120
 
@@ -140,8 +129,23 @@ def run_inference():
140
  if st.session_state['kbvqa']:
141
  image_qa_app(st.session_state['kbvqa'])
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  else:
144
  st.write('Model is not ready for inference yet')
 
145
 
146
 
147
  # Main function
 
92
  def run_inference():
93
  st.title("Run Inference")
94
 
95
+ method = st.selectbox("Choose a method:", ["Fine-Tuned Model", "In-Context Learning (n-shots)"], index=0)
96
+ detection_model = st.selectbox("Choose a model for object detection:", ["yolov5", "detic"], index=0)
97
+ confidence_level = st.slider("Select minimum detection confidence level", min_value=0.1, max_value=0.9, value=0.2 if detection_model == "yolov5" else 0.4, step=0.1)
98
+
99
+ # Check for changes in model or confidence level
100
+ model_changed = (st.session_state.get('detection_model') != detection_model)
101
+ confidence_changed = (st.session_state.get('confidence_level') != confidence_level)
102
+
103
+ if model_changed or confidence_changed:
104
+ st.session_state['detection_model'] = detection_model
105
+ st.session_state['confidence_level'] = confidence_level
106
+ st.warning("Detection model or confidence level changed. Please reload the model.")
 
 
 
 
 
 
 
 
 
 
 
107
 
108
 
109
 
 
129
  if st.session_state['kbvqa']:
130
  image_qa_app(st.session_state['kbvqa'])
131
 
132
+
133
+ if st.button('Load Model'):
134
+ if st.session_state.get('kbvqa') and not model_changed and not confidence_changed:
135
+ st.write("Model already loaded.")
136
+ else:
137
+ st.text("Loading the model will take no more than a few minutes . .")
138
+ st.session_state['kbvqa'] = prepare_kbvqa_model(detection_model)
139
+ st.session_state['kbvqa'].detection_confidence = confidence_level
140
+ st.success("Model loaded with updated settings.")
141
+
142
+ if st.session_state.get('kbvqa'):
143
+ st.write("Model is ready for inference.")
144
+ image_qa_app(st.session_state['kbvqa'])
145
+
146
  else:
147
  st.write('Model is not ready for inference yet')
148
+ # here goes the code for n-shot learning
149
 
150
 
151
  # Main function