taimoor61 commited on
Commit
4d200f3
Β·
1 Parent(s): 29c65a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -29
app.py CHANGED
@@ -1,40 +1,25 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- # Load pre-trained emotion classification model
5
  model_checkpoint = "MuntasirHossain/RoBERTa-base-finetuned-emotion"
6
- emotion_model = pipeline("text-classification", model=model_checkpoint)
7
 
8
- def classify_and_visualize_emotion(text):
9
- # Get the predicted emotion label
10
- emotion_label = emotion_model(text)[0]["label"]
11
-
12
- # Map emotion labels to corresponding emojis
13
- emoji_mapping = {
14
- "joy": "πŸ˜„",
15
- "sadness": "😒",
16
- "love": "❀️",
17
- "anger": "😑",
18
- "fear": "😱",
19
- "surprise": "😲",
20
- }
21
-
22
- # Get the corresponding emoji for the predicted emotion
23
- predicted_emoji = emoji_mapping.get(emotion_label, "πŸ€”")
24
 
25
- return f"{emotion_label.capitalize()} {predicted_emoji}"
26
 
27
- # Define interface title and description
28
- title = "Emotion Classifier with Emoji Visualization"
29
- description = "This AI model classifies text expressions into six emotions: joy, sadness, love, anger, fear, and surprise. The result is visualized with emojis."
30
 
31
- # Set up Gradio Interface with HTML visualization
32
- iface = gr.Interface(
33
- fn=classify_and_visualize_emotion,
 
 
 
34
  inputs="textbox",
35
- outputs=gr.Html(),
36
  title=title,
 
37
  description=description,
38
- )
39
-
40
- iface.launch()
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
 
4
  model_checkpoint = "MuntasirHossain/RoBERTa-base-finetuned-emotion"
 
5
 
6
+ model = pipeline("text-classification", model=model_checkpoint)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
 
8
 
9
+ def classify(text):
10
+ label = model(text)[0]["label"]
11
+ return label
12
 
13
+ description = "This AI model is trained to classify texts expressing human emotion into six categories: sadness, joy, love, anger, fear, and surprise."
14
+ title = "Classify Texts Expressing Emotion"
15
+ # theme = "peach"
16
+ examples=[["This is such a beautiful place"]]
17
+
18
+ gr.Interface(fn=classify,
19
  inputs="textbox",
20
+ outputs="text",
21
  title=title,
22
+ # theme = theme,
23
  description=description,
24
+ examples=examples,
25
+ ).launch()