Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -99,19 +99,10 @@ def respond(
|
|
| 99 |
message,
|
| 100 |
history: list[tuple[str, str]],
|
| 101 |
threshold,
|
| 102 |
-
is_multiple
|
| 103 |
-
chosen_model_id
|
| 104 |
):
|
| 105 |
global codes_emb
|
| 106 |
global undetected
|
| 107 |
-
global model
|
| 108 |
-
global model_id
|
| 109 |
-
global codes_emb
|
| 110 |
-
|
| 111 |
-
if chosen_model_id != model_id:
|
| 112 |
-
model = SentenceTransformer(chosen_model_id, trust_remote_code=True)
|
| 113 |
-
model_id = chosen_model_id
|
| 114 |
-
codes_emb = model.encode([x[6:] for x in codes])
|
| 115 |
|
| 116 |
undetected_code = undetected[:3]
|
| 117 |
|
|
@@ -198,6 +189,20 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
| 198 |
# )
|
| 199 |
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
with gr.Blocks() as demo:
|
| 202 |
# Add header title and description
|
| 203 |
gr.Markdown("# List of Request Numbers")
|
|
@@ -205,13 +210,15 @@ with gr.Blocks() as demo:
|
|
| 205 |
gr.Markdown("# Valid License Plate Number Criteria:")
|
| 206 |
gr.Markdown("(1-2 letters) (4 numbers) (1-3 letters)")
|
| 207 |
|
|
|
|
|
|
|
| 208 |
# Add chat interface
|
| 209 |
chat_interface = gr.ChatInterface(
|
| 210 |
respond,
|
| 211 |
additional_inputs=[
|
| 212 |
gr.Number(0.5, label="confidence threshold", show_label=True, minimum=0., maximum=1.0, step=0.1),
|
| 213 |
gr.Checkbox(label="multiple", info="Allow multiple request code numbers"),
|
| 214 |
-
|
| 215 |
]
|
| 216 |
)
|
| 217 |
|
|
|
|
| 99 |
message,
|
| 100 |
history: list[tuple[str, str]],
|
| 101 |
threshold,
|
| 102 |
+
is_multiple
|
|
|
|
| 103 |
):
|
| 104 |
global codes_emb
|
| 105 |
global undetected
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
undetected_code = undetected[:3]
|
| 108 |
|
|
|
|
| 189 |
# )
|
| 190 |
|
| 191 |
|
| 192 |
+
def reload(chosen_model_id):
|
| 193 |
+
global model
|
| 194 |
+
global model_id
|
| 195 |
+
global codes_emb
|
| 196 |
+
|
| 197 |
+
if chosen_model_id != model_id:
|
| 198 |
+
model = SentenceTransformer(chosen_model_id, trust_remote_code=True)
|
| 199 |
+
model_id = chosen_model_id
|
| 200 |
+
codes_emb = model.encode([x[6:] for x in codes])
|
| 201 |
+
return {"message": f"Model {chosen_model_id} has been succesfully loaded!"}
|
| 202 |
+
return {"messsage": f"Model {chosen_model_id} is ready!"}
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
with gr.Blocks() as demo:
|
| 207 |
# Add header title and description
|
| 208 |
gr.Markdown("# List of Request Numbers")
|
|
|
|
| 210 |
gr.Markdown("# Valid License Plate Number Criteria:")
|
| 211 |
gr.Markdown("(1-2 letters) (4 numbers) (1-3 letters)")
|
| 212 |
|
| 213 |
+
reload_model = gr.Interface(fn=image_classifier, inputs=[gr.Dropdown(choices=model_ids, value=model_id)], outputs="label")
|
| 214 |
+
|
| 215 |
# Add chat interface
|
| 216 |
chat_interface = gr.ChatInterface(
|
| 217 |
respond,
|
| 218 |
additional_inputs=[
|
| 219 |
gr.Number(0.5, label="confidence threshold", show_label=True, minimum=0., maximum=1.0, step=0.1),
|
| 220 |
gr.Checkbox(label="multiple", info="Allow multiple request code numbers"),
|
| 221 |
+
|
| 222 |
]
|
| 223 |
)
|
| 224 |
|