Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,47 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Laad het sentimentanalyse-model
|
|
|
5 |
classifier = pipeline("sentiment-analysis")
|
6 |
|
7 |
-
# Functie om
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
#
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
return output
|
16 |
|
17 |
-
# Gradio-interface
|
18 |
demo = gr.Interface(
|
19 |
-
fn=
|
20 |
-
inputs=gr.Textbox(lines=
|
21 |
outputs="text",
|
22 |
-
title="
|
23 |
-
description="Voer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
)
|
25 |
|
26 |
# Start de app
|
27 |
demo.launch()
|
28 |
|
29 |
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Laad het vertaalmodel (meertalig β Engels) en het sentimentanalyse-model (Engels)
|
5 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-mul-en")
|
6 |
classifier = pipeline("sentiment-analysis")
|
7 |
|
8 |
+
# Functie om tekst te vertalen en sentimentanalyse uit te voeren
|
9 |
+
def analyze_multilingual_sentiment(text):
|
10 |
+
if not text.strip():
|
11 |
+
return "β οΈ Voer een tekst in voor analyse."
|
12 |
+
|
13 |
+
# Stap 1: Vertaal de tekst naar Engels
|
14 |
+
translated_text = translator(text)[0]['translation_text']
|
15 |
+
|
16 |
+
# Stap 2: Voer sentimentanalyse uit op de vertaalde tekst
|
17 |
+
result = classifier(translated_text)[0]
|
18 |
+
|
19 |
+
# Stap 3: Geef de output terug met oorspronkelijke tekst, vertaling en sentimentanalyse
|
20 |
+
output = f"""
|
21 |
+
π **Originele tekst:** {text}
|
22 |
+
π **Vertaling (Engels):** {translated_text}
|
23 |
+
π **Sentimentanalyse:** {result['label']} ({result['score']:.2f})
|
24 |
+
"""
|
25 |
return output
|
26 |
|
27 |
+
# Maak een Gradio-interface
|
28 |
demo = gr.Interface(
|
29 |
+
fn=analyze_multilingual_sentiment,
|
30 |
+
inputs=gr.Textbox(lines=3, placeholder="Voer hier een tekst in in elke taal..."),
|
31 |
outputs="text",
|
32 |
+
title="π Meertalige Sentimentanalyse",
|
33 |
+
description="Voer een tekst in in elke taal. De app vertaalt de tekst naar Engels en voert sentimentanalyse uit.",
|
34 |
+
examples=[
|
35 |
+
["Ik hou van programmeren!"],
|
36 |
+
["Je suis très fatigué aujourd'hui."],
|
37 |
+
["Hoy hace mucho frΓo y estoy triste."],
|
38 |
+
["θΏι¨η΅ε½±ε€ͺζ£δΊοΌ"],
|
39 |
+
["Das Wetter ist schrecklich, ich hasse es."]
|
40 |
+
]
|
41 |
)
|
42 |
|
43 |
# Start de app
|
44 |
demo.launch()
|
45 |
|
46 |
|
47 |
+
|