Spaces:
Sleeping
Sleeping
File size: 1,477 Bytes
3c3ff47 65f5aa2 3c3ff47 903f7b1 65f5aa2 3c3ff47 903f7b1 4a094f8 903f7b1 e2ad6e1 903f7b1 b6919df e2ad6e1 903f7b1 3c3ff47 707c991 903f7b1 707c991 903f7b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import gradio as gr
from transformers import pipeline
# Load sentiment analysis pipeline
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
# Function to analyze user's mood based on input
def analyze_mood(user_input):
# Analyze the mood from input text
results = sentiment_analysis(user_input)
mood_summary = {"POSITIVE": 0, "NEGATIVE": 0, "NEUTRAL": 0}
suggestions = []
# Loop through all results and summarize sentiments
for result in results:
label = result["label"]
score = result["score"]
mood_summary[label] += score
# Determine the dominant mood
dominant_mood = max(mood_summary, key=mood_summary.get)
# Provide suggestions based on mood
if dominant_mood == "POSITIVE":
suggestion = "Keep enjoying your day π"
elif dominant_mood == "NEGATIVE":
suggestion = "Try playing a game you like or practice some deep breathing exercises. It might help! π"
else:
suggestion = "You're doing well! Stay calm πΈ"
# Return mood and suggestion
return f"Your mood seems mostly {dominant_mood.lower()}.", suggestion
inputs = gr.Textbox(label="How are you feeling today?", placeholder="Type your thoughts here...")
outputs = gr.Textbox(label="Mood and Suggestion")
interface = gr.Interface(fn=analyze_mood, inputs=inputs, outputs=outputs, title="Mood Analyzer with Suggestions")
interface.launch()
|