Spaces:
Running
Running
Commit
·
4201593
1
Parent(s):
fbdc35c
app update
Browse files
app.py
CHANGED
@@ -1,19 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
import uvicorn
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
|
8 |
-
#
|
9 |
def classify_emotion(text):
|
10 |
-
|
11 |
-
return
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
if __name__ == "__main__":
|
19 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Load the BERT-Emotions-Classifier model
|
5 |
+
classifier = pipeline("text-classification", model="ayoubkirouane/BERT-Emotions-Classifier")
|
6 |
|
7 |
+
# Define the prediction function for emotion classification
|
8 |
def classify_emotion(text):
|
9 |
+
result = classifier(text)
|
10 |
+
return result[0]['label'], result[0]['score']
|
11 |
|
12 |
+
# Define the Gradio interface
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=classify_emotion, # function that will classify emotion
|
15 |
+
inputs=gr.Textbox(), # input text box
|
16 |
+
outputs=[gr.Textbox(), gr.Textbox()], # output emotion label and score
|
17 |
+
live=True # Enable live mode (optional)
|
18 |
+
)
|
19 |
|
20 |
+
# Launch the Gradio interface as an API
|
21 |
+
iface.launch(share=True)
|
|
|
|
|
|