Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,29 +16,30 @@ model_path = hf_hub_download(
|
|
| 16 |
# Cargar el modelo usando la ruta absoluta
|
| 17 |
model = joblib.load(model_path)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
return pred
|
| 23 |
|
| 24 |
-
def
|
| 25 |
-
|
| 26 |
-
df["Prediction"] = model.predict(df["title"] + " " + df["abstract"])
|
| 27 |
-
return df
|
| 28 |
|
|
|
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Cargar el modelo usando la ruta absoluta
|
| 17 |
model = joblib.load(model_path)
|
| 18 |
|
| 19 |
+
# --- Funciones ---
|
| 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 |
+
# --- Blocks ---
|
| 27 |
with gr.Blocks() as demo:
|
| 28 |
+
# Endpoint single prediction
|
| 29 |
+
single_input = gr.Textbox(label="Input text")
|
| 30 |
+
single_output = gr.Textbox(label="Predicted category")
|
| 31 |
+
single_btn = gr.Button("Predict")
|
| 32 |
+
single_btn.click(predict_single, inputs=single_input, outputs=single_output)
|
| 33 |
+
|
| 34 |
+
# Endpoint batch prediction
|
| 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)
|