Pavitra07 commited on
Commit
45f9552
·
1 Parent(s): 079eb10

Add Gradio app and requirements

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requires.txt +3 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.environ["TRANSFORMERS_NO_TF"] = "1"
3
+
4
+ from transformers import pipeline
5
+ import gradio as gr
6
+
7
+ # Load the emotion detection model
8
+ emotion_classifier = pipeline("text-classification",
9
+ model="bhadresh-savani/distilbert-base-uncased-emotion")
10
+
11
+ # Define the emotion detection function
12
+ def detect_emotion(text):
13
+ result = emotion_classifier(text)
14
+ emotion = result[0]['label']
15
+ score = round(result[0]['score'], 3)
16
+ return f"Predicted Emotion: {emotion} (Confidence: {score})"
17
+
18
+ # Create the Gradio interface
19
+ interface = gr.Interface(
20
+ fn=detect_emotion,
21
+ inputs=gr.Textbox(lines=3, placeholder="Type your sentence here..."),
22
+ outputs="text",
23
+ title="Emotion Detector",
24
+ description="Enter a sentence and let this AI detect the emotion behind it!"
25
+ )
26
+
27
+ # Launch with public link
28
+ interface.launch(share=True)
requires.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch