File size: 1,329 Bytes
3c3ff47 65f5aa2 3c3ff47 d720951 65f5aa2 3c3ff47 707c991 4a094f8 d720951 65f5aa2 4a094f8 707c991 4a094f8 65f5aa2 4a094f8 65f5aa2 3c3ff47 18faac8 3c3ff47 4a094f8 707c991 4a094f8 18faac8 |
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 |
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
result = sentiment_analysis(user_input)[0]
# Define mood and suggestion based on sentiment analysis
mood = "Neutral" # Default mood
suggestion = "You're doing okay! Stay calm πΈ" # Default suggestion
# Adjust mood based on analysis
if result["label"] == "POSITIVE" and result["score"] > 0.85:
mood = "Happy"
suggestion = "Keep doing what you're doing! π"
elif result["label"] == "NEGATIVE" and result["score"] > 0.85:
mood = "Sad"
suggestion = "Try to talk to someone, or take a break π‘"
# Return mood and suggestion without parentheses and quotes
return "Your mood is: " + mood + ". " + suggestion
# Set up Gradio inputs and outputs
inputs = gr.Textbox(label="How are you feeling today?", placeholder="Type your thoughts here...")
outputs = gr.Textbox(label="Mood and Suggestion")
# Launch the Gradio interface
gr.Interface(fn=analyze_mood, inputs=inputs, outputs=outputs, title="Mood Analyzer").launch() |