Spaces:
Sleeping
Sleeping
File size: 1,313 Bytes
3c3ff47 65f5aa2 3c3ff47 61c54ed 65f5aa2 3c3ff47 61c54ed 4a094f8 61c54ed 903f7b1 61c54ed 903f7b1 61c54ed 903f7b1 61c54ed b6919df 61c54ed 903f7b1 61c54ed 3c3ff47 61c54ed 707c991 903f7b1 707c991 61c54ed |
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 |
import gradio as gr
from transformers import pipeline
# Load the sentiment analysis pipeline
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
# Function to analyze mood
def analyze_mood(user_input):
# analyze mood from text
results = sentiment_analysis(user_input)
mood_summary = {"POSITIVE": 0, "NEGATIVE": 0, "NEUTRAL": 0}
suggestions = []
# sum up scores
for result in results:
label = result["label"]
score = result["score"]
mood_summary[label] += score
# find most mood
main_mood = max(mood_summary, key=mood_summary.get)
# suggest based on mood
if main_mood == "POSITIVE":
suggestion = "Keep enjoying your day :)"
elif main_mood == "NEGATIVE":
suggestion = "Maybe play a game or breathe deeply could help!"
else:
suggestion = "Doing well! stay calm"
# return mood and suggestion
return "Your mood seems mostly " + main_mood.lower() + ". " + suggestion
inputs = gr.Textbox(label="How are you today?", placeholder="Type your feelings 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() |