I2C-UHU commited on
Commit
c389086
1 Parent(s): 50c4b73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -10
app.py CHANGED
@@ -1,16 +1,62 @@
1
  import gradio as gr
 
2
 
3
- '''
4
- def under_construction():
5
- return "classificator under construction"
6
 
7
- gr.Interface(fn=under_construction, inputs=None, outputs="text").launch()
8
- '''
 
 
 
 
9
 
 
 
10
 
11
- txt = "TEXT CLASSIFICATOR UNDER CONSTRUCTION"
 
12
 
13
- with gr.Blocks() as demo:
14
- gr.Textbox(txt)
15
-
16
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
3
 
4
+ # Importa aquí tus clasificadores de texto en inglés y español
5
+ # Puedes usar modelos de tu elección y cargarlos usando herramientas como TensorFlow, PyTorch, etc.
 
6
 
7
+ # Definir las funciones que se utilizarán para clasificar el texto en inglés y español
8
+ def classify_english_text(text):
9
+ # Coloca aquí la lógica para clasificar el texto en inglés
10
+ # Puedes usar el clasificador de texto en inglés que tengas cargado
11
+ pipe = pipeline("text-classification", model="I2C-UHU/NT-Grief_EN")
12
+ label = pipe(text)[0]['label']
13
 
14
+ if label == "LABEL_1":
15
+ label = label + " --> Message with non-traumatic grief content"
16
 
17
+ elif label == "LABEL_0":
18
+ label = label + " --> Message without non-traumatic grief content"
19
 
20
+ return label, pipe(text)[0]['score']
21
+
22
+ def classify_spanish_text(text):
23
+ # Coloca aquí la lógica para clasificar el texto en español
24
+ # Puedes usar el clasificador de texto en español que tengas cargado
25
+ pipe = pipeline("text-classification", model="I2C-UHU/NT-Grief_SP")
26
+ label = pipe(text)[0]['label']
27
+
28
+ if label == "LABEL_1":
29
+ label = label + " --> Message with non-traumatic grief content"
30
+
31
+ elif label == "LABEL_0":
32
+ label = label + " --> Message without non-traumatic grief content"
33
+
34
+ return label, pipe(text)[0]['score']
35
+
36
+ # Función para redirigir a la función de clasificación correspondiente según el idioma seleccionado
37
+ def classify_text(language, text):
38
+ if language == "English":
39
+ return classify_english_text(text)
40
+ elif language == "Español":
41
+ return classify_spanish_text(text)
42
+ else:
43
+ return "Por favor, seleccione un idioma válido / Please select a valid language.",0
44
+
45
+ examples = [
46
+ ["el jefe del gobierno local dijo que la muerte de thomas schäfer puede estar relacionada con preocupaciones debido a la crisis por la pandemia del coronavirus."],
47
+ ["I don't know who but the way the coronavirus pandemic coronavirus pandemic is causing some people to be scared to death some people are dying of fear, it is worth remembering that death is worth remembering that death comes at the right precise moment, not before, not after after..."],
48
+ ]
49
+
50
+ # Definir la interfaz Gradio
51
+ iface = gr.Interface(
52
+ fn=classify_text, # Como vamos a usar dos funciones diferentes, dejamos este valor como None
53
+ inputs=[
54
+ gr.Radio(["Español", "English"], label="Elija el idioma / Choose the language"),
55
+ gr.Textbox(label="Texto / Text")
56
+ ],
57
+ outputs=[gr.Textbox(label = "Prediction"), gr.Number(label = "Probability")], # Salida de texto con el resultado de la clasificación
58
+ title = "Non Traumatic Grief Detector",
59
+ )
60
+
61
+ # Ejecutar la interfaz Gradio
62
+ iface.launch()