Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,30 +16,26 @@ model_path = hf_hub_download(
|
|
| 16 |
# Cargar el modelo usando la ruta absoluta
|
| 17 |
model = joblib.load(model_path)
|
| 18 |
|
| 19 |
-
#
|
| 20 |
def predict_single(text):
|
| 21 |
return model.predict([text])[0]
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def predict_batch(texts):
|
| 24 |
return [model.predict([t])[0] for t in texts]
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
batch_input = gr.Textbox(label="Batch texts (comma separated)")
|
| 36 |
-
batch_output = gr.Textbox(label="Predictions (comma separated)")
|
| 37 |
-
batch_btn = gr.Button("Predict Batch")
|
| 38 |
-
batch_btn.click(
|
| 39 |
-
lambda x: predict_batch(x.split(",")),
|
| 40 |
-
inputs=batch_input,
|
| 41 |
-
outputs=batch_output
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
# --- Lanzar en API mode ---
|
| 45 |
-
demo.launch(server_name="0.0.0.0", server_port=7860, api_mode=True)
|
|
|
|
| 16 |
# Cargar el modelo usando la ruta absoluta
|
| 17 |
model = joblib.load(model_path)
|
| 18 |
|
| 19 |
+
# Single prediction
|
| 20 |
def predict_single(text):
|
| 21 |
return model.predict([text])[0]
|
| 22 |
|
| 23 |
+
single_interface = gr.Interface(
|
| 24 |
+
fn=predict_single,
|
| 25 |
+
inputs=gr.Textbox(label="Input text"),
|
| 26 |
+
outputs=gr.Textbox(label="Predicted category")
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Batch prediction
|
| 30 |
def predict_batch(texts):
|
| 31 |
return [model.predict([t])[0] for t in texts]
|
| 32 |
|
| 33 |
+
batch_interface = gr.Interface(
|
| 34 |
+
fn=predict_batch,
|
| 35 |
+
inputs=gr.Textbox(label="Batch texts (comma separated)"),
|
| 36 |
+
outputs=gr.Textbox(label="Predictions (comma separated)")
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Lanzar ambos
|
| 40 |
+
single_interface.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
| 41 |
+
batch_interface.launch(server_name="0.0.0.0", server_port=7861, share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|