|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english") |
|
|
|
|
|
def analyze_mood(user_input): |
|
result = sentiment_analysis(user_input)[0] |
|
|
|
|
|
if result["label"] == "POSITIVE": |
|
mood = "Happy" |
|
suggestion = "Keep enjoying your day π" |
|
elif result["label"] == "NEGATIVE": |
|
mood = "Sad" |
|
suggestion = "Try playing a game you like or practice some deep breathing exercises it might help!π" |
|
else: |
|
mood = "Neutral" |
|
suggestion = "You're doing well! Stay calm πΈ" |
|
|
|
|
|
return "Your mood is " + mood + ". " + suggestion |
|
|
|
inputs = gr.Textbox(label="How are you feeling today?", placeholder="Type your thoughts here...") |
|
outputs = gr.Textbox(label="Mood and Suggestion") |
|
|
|
gr.Interface(fn=analyze_mood, inputs=inputs, outputs=outputs, title="Mood Analyzer with Suggestions").launch() |
|
|