kgemera commited on
Commit
aa253a6
·
verified ·
1 Parent(s): 467bc07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -21
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
- # --- 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)
 
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)