Spaces:
Sleeping
Sleeping
Commit
·
faff5a6
1
Parent(s):
60874e5
Nueva funcionalidad de subir PDF
Browse files- README.md +1 -1
- app.py +34 -24
- requirements.txt +2 -1
README.md
CHANGED
@@ -15,6 +15,6 @@ Este proyecto utiliza el modelo DistilBETO para analizar sentimientos en textos
|
|
15 |
|
16 |
## Cómo usar
|
17 |
|
18 |
-
1. Ingresa un texto en español en el campo de entrada.
|
19 |
2. Presiona "Submit" para analizar el sentimiento del texto.
|
20 |
3. El resultado mostrará la categoría de sentimiento y la puntuación correspondiente.
|
|
|
15 |
|
16 |
## Cómo usar
|
17 |
|
18 |
+
1. Ingresa un texto en español en el campo de entrada o bien selecciona un PDF.
|
19 |
2. Presiona "Submit" para analizar el sentimiento del texto.
|
20 |
3. El resultado mostrará la categoría de sentimiento y la puntuación correspondiente.
|
app.py
CHANGED
@@ -1,32 +1,42 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
sentiment_analysis = pipeline("sentiment-analysis", model=modelo, tokenizer=modelo)
|
7 |
|
8 |
-
def
|
9 |
-
|
10 |
-
label =
|
11 |
-
score =
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
)
|
|
|
|
|
|
|
|
|
31 |
|
32 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from PyPDF2 import PdfReader
|
4 |
|
5 |
+
# Inicializar el modelo de análisis de sentimiento con DistilBETO
|
6 |
+
sentiment_analysis = pipeline("sentiment-analysis", model="finiteautomata/beto-sentiment-analysis")
|
|
|
7 |
|
8 |
+
def analyze_text(text):
|
9 |
+
result = sentiment_analysis(text)
|
10 |
+
label = result[0]['label']
|
11 |
+
score = result[0]['score']
|
12 |
+
return f"Label: {label}, Score: {score}"
|
13 |
|
14 |
+
def analyze_pdf(pdf):
|
15 |
+
# Leer el contenido del PDF
|
16 |
+
pdf_reader = PdfReader(pdf)
|
17 |
+
text = ""
|
18 |
+
for page in pdf_reader.pages:
|
19 |
+
text += page.extract_text() + "\n"
|
20 |
+
|
21 |
+
# Análisis del contenido del PDF
|
22 |
+
result = sentiment_analysis(text)
|
23 |
+
label = result[0]['label']
|
24 |
+
score = result[0]['score']
|
25 |
+
return f"Label: {label}, Score: {score}"
|
26 |
|
27 |
+
# Interfaz de Gradio con dos inputs: texto o PDF
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
gr.Markdown("# Análisis de Sentimientos con DistilBETO")
|
30 |
+
gr.Markdown("Ingrese un texto en español o cargue un PDF para analizar su sentimiento usando DistilBETO.")
|
31 |
+
|
32 |
+
with gr.Row():
|
33 |
+
text_input = gr.Textbox(label="Texto", placeholder="Escribe aquí el texto para análisis")
|
34 |
+
pdf_input = gr.File(label="Cargar PDF", type="file")
|
35 |
+
|
36 |
+
output = gr.Textbox(label="Resultado")
|
37 |
+
|
38 |
+
submit_btn = gr.Button("Submit")
|
39 |
+
submit_btn.click(fn=analyze_text, inputs=text_input, outputs=output)
|
40 |
+
submit_btn.click(fn=analyze_pdf, inputs=pdf_input, outputs=output)
|
41 |
|
42 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
gradio==4.44.1
|
2 |
transformers
|
3 |
-
torch
|
|
|
|
1 |
gradio==4.44.1
|
2 |
transformers
|
3 |
+
torch
|
4 |
+
PyPDF2
|