walkermanj commited on
Commit
222e0a9
Β·
verified Β·
1 Parent(s): c8b615f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -1,25 +1,23 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the pretrained sentiment pipeline
5
- sentiment_pipeline = pipeline("sentiment-analysis")
6
 
7
- def predict_sentiment(text):
8
- result = sentiment_pipeline(text)[0]
9
  label = result["label"]
10
-
11
- if label == "POSITIVE":
12
- return "βœ… POSITIVE 😊"
13
- else:
14
- return "❌ NEGATIVE 😠"
15
 
16
  # Gradio Interface
17
  demo = gr.Interface(
18
- fn=predict_sentiment,
19
- inputs=gr.Textbox(lines=3, placeholder="Type your sentence here..."),
20
  outputs="text",
21
- title="πŸ’¬ LM Studios Sentiment Detector",
22
- description="Now powered by a Hugging Face transformer model for smarter predictions.",
23
  theme="default",
24
  flagging_mode="never"
25
  )
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the emotion detection pipeline
5
+ emotion_pipeline = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
6
 
7
+ def predict_emotion(text):
8
+ result = emotion_pipeline(text)[0]
9
  label = result["label"]
10
+ score = result["score"]
11
+
12
+ return f"🧠 Emotion: {label.upper()} ({score:.2f})"
 
 
13
 
14
  # Gradio Interface
15
  demo = gr.Interface(
16
+ fn=predict_emotion,
17
+ inputs=gr.Textbox(lines=3, placeholder="Type something emotional..."),
18
  outputs="text",
19
+ title="🎭 LM Studios Emotion Detector",
20
+ description="Now with real emotional awareness: detects joy, anger, sadness, fear, love, and surprise.",
21
  theme="default",
22
  flagging_mode="never"
23
  )