Spaces:
Runtime error
Runtime error
Commit
·
caeeddb
1
Parent(s):
bc1cef3
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
def analyze(text):
|
6 |
+
classifier = pipeline("text-classification", model="ayoubkirouane/BERT-Emotions-Classifier", return_all_scores=True)
|
7 |
+
results = classifier(text)
|
8 |
+
|
9 |
+
# Extract and format the emotion labels and scores
|
10 |
+
formatted_results = [{"Emotion": item['label'], "Score": item['score']} for item in results[0]]
|
11 |
+
|
12 |
+
return pd.DataFrame(formatted_results)
|
13 |
+
|
14 |
+
examples = ["Walking alone in the dark forest, he couldn't shake the feeling of fear creeping over him." ,
|
15 |
+
"Winning the championship brought tears of joy to the entire team."]
|
16 |
+
# Create a Gradio interface
|
17 |
+
iface = gr.Interface(fn=analyze,
|
18 |
+
inputs="text",
|
19 |
+
outputs=gr.outputs.Dataframe(type="pandas"),
|
20 |
+
allow_flagging=False ,
|
21 |
+
examples=examples ,
|
22 |
+
title="BERT Emotion Analysis App" ,
|
23 |
+
description="Enter a piece of text, and this app will analyze its emotional content using a BERT-Emotions-Classifier model.",
|
24 |
+
)
|
25 |
+
|
26 |
+
# Launch the app
|
27 |
+
iface.launch(debug=True)
|