feralvam commited on
Commit
2374872
1 Parent(s): 671f163

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from transformers import pipeline
4
+
5
+ title = "Automatic Readability Assessment of Texts in Spanish"
6
+
7
+ description = """
8
+ Is a text **complex** or **simple**? Can it be understood by someone learning Spanish with a **basic**, **intermediate** or **advanced** knowledge of the language (*coming soon!*)? Find out with our models below!
9
+ """
10
+
11
+ article = """
12
+
13
+ ### What's Readability Assessment?
14
+
15
+ [Automatic Readability Assessment](https://arxiv.org/abs/2105.00973) consists of determining "how difficult" it could be to read and understand a piece of text.
16
+ This could be estimated using readability formulas, such as [Flesch for English](https://en.wikipedia.org/wiki/Flesch%E2%80%93Kincaid_readability_tests) or [similar ones for Spanish](https://www.siicsalud.com/imagenes/blancopet1.pdf).
17
+ However, their dependance on surface statistics (e.g. average sentence length) makes them unreliable.
18
+ As such, developing models that could estimate a text's readability by "looking beyond the surface" is a necessity.
19
+
20
+ ### Goal
21
+
22
+ We aim to contribute to the development of **neural models for readability assessment for Spanish**, following previous work for [English](https://aclanthology.org/2021.cl-1.6/) and [Filipino](https://aclanthology.org/2021.ranlp-1.69/).
23
+
24
+
25
+ ### More Information
26
+
27
+ Details about how we trained these models can be found in our [report](https://wandb.ai/readability-es/readability-es/reports/Texts-Readability-Analysis-for-Spanish--VmlldzoxNzU2MDUx).
28
+
29
+
30
+ ### Team
31
+
32
+ - [Laura Vásquez-Rodríguez](https://lmvasque.github.io/)
33
+ - Pedro Cuenca
34
+ - Sergio Morales
35
+ - [Fernando Alva-Manchego](https://feralvam.github.io/)
36
+
37
+ """
38
+
39
+ examples = [
40
+ ["Esta es una frase simple.", "simple or complex?"],
41
+ ["La ciencia nos enseña, en efecto, a someter nuestra razón a la verdad y a conocer y juzgar las cosas como son, es decir, como ellas mismas eligen ser y no como quisiéramos que fueran.", "simple or complex?"],
42
+ ]
43
+
44
+
45
+ model_binary = pipeline("sentiment-analysis", model="hackathon-pln-es/readability-es-sentences", return_all_scores=True)
46
+
47
+
48
+ def predict(text, levels):
49
+ if levels == 0:
50
+ predicted_scores = model_binary(text)[0]
51
+
52
+ output_scores = {}
53
+ for e in predicted_scores:
54
+ output_scores[e['label']] = e['score']
55
+
56
+ return output_scores
57
+
58
+
59
+ iface = gr.Interface(
60
+ fn=predict,
61
+ inputs=[
62
+ gr.inputs.Textbox(lines=7, placeholder="Write a text in Spanish.", label="Text in Spanish"),
63
+ # gr.inputs.Radio(choices=["simple or complex?", "basic, intermediate, or advanced?"], type="index", label="Readability Levels"),
64
+ gr.inputs.Radio(choices=["simple or complex?"], type="index", label="Readability Levels"),
65
+ ],
66
+ outputs=[
67
+ gr.outputs.Label(num_top_classes=3, label="Predicted Readability Level")
68
+ ],
69
+ theme="huggingface",
70
+ title = title, description = description, article = article, examples=examples,
71
+ allow_flagging="never",
72
+ )
73
+ iface.launch()