kgemera commited on
Commit
a3de2b3
verified
1 Parent(s): a915d61

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import pandas as pd
4
+
5
+ # Cargar el modelo
6
+ model = joblib.load("classification_model.pkl")
7
+
8
+ def predict_text(title, abstract):
9
+ text = f"{title} {abstract}"
10
+ pred = model.predict([text])[0]
11
+ return pred
12
+
13
+ def predict_file(file):
14
+ df = pd.read_csv(file, sep=";")
15
+ df["Prediction"] = model.predict(df["title"] + " " + df["abstract"])
16
+ return df
17
+
18
+ with gr.Blocks() as demo:
19
+ gr.Markdown("# 馃┖ Medical Text Classifier")
20
+
21
+ with gr.Tab("Texto individual"):
22
+ title = gr.Textbox(label="T铆tulo")
23
+ abstract = gr.Textbox(label="Abstract")
24
+ output = gr.Textbox(label="Predicci贸n")
25
+ btn = gr.Button("Clasificar")
26
+ btn.click(predict_text, inputs=[title, abstract], outputs=output)
27
+
28
+ with gr.Tab("Archivo CSV"):
29
+ file_input = gr.File(label="Subir CSV", file_types=[".csv"])
30
+ file_output = gr.Dataframe()
31
+ file_input.change(predict_file, inputs=file_input, outputs=file_output)
32
+
33
+ demo.launch()