Madiharehan commited on
Commit
01c3c58
β€’
1 Parent(s): 821a21e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the pre-trained model (cached for performance)
5
+ def load_model():
6
+ return pipeline('sentiment-analysis', model='cardiffnlp/twitter-roberta-base-sentiment')
7
+
8
+ sentiment_model = load_model()
9
+
10
+ # Define the function to analyze sentiment
11
+ def analyze_sentiment(user_input):
12
+ result = sentiment_model(user_input)[0]
13
+ sentiment = result['label']
14
+
15
+ if sentiment in ['NEGATIVE', 'NEUTRAL']:
16
+ return "Stay positive! 🌟 You can handle anything that comes your way."
17
+ return "You're on the right track! Keep shining! 🌞"
18
+
19
+ # Gradio UI
20
+ def chatbot_ui():
21
+ # Define the interface
22
+ interface = gr.Interface(
23
+ fn=analyze_sentiment,
24
+ inputs=gr.Textbox(label="Enter your text here:"),
25
+ outputs=gr.Textbox(label="Motivational Message"),
26
+ title="Student Sentiment Analysis Chatbot",
27
+ description="This chatbot detects your mood and provides positive or motivational messages."
28
+ )
29
+
30
+ return interface
31
+
32
+ # Launch the interface
33
+ if __name__ == "__main__":
34
+ chatbot_ui().launch()
35
+