Madiharehan
commited on
Commit
β’
6db8709
1
Parent(s):
3e75920
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
-
import
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Load the pre-trained model (cached for performance)
|
5 |
-
@st.cache_resource
|
6 |
def load_model():
|
7 |
return pipeline('sentiment-analysis', model='cardiffnlp/twitter-roberta-base-sentiment')
|
8 |
|
@@ -17,17 +16,19 @@ def analyze_sentiment(user_input):
|
|
17 |
return "Stay positive! π You can handle anything that comes your way."
|
18 |
return "You're on the right track! Keep shining! π"
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
user_input = st.text_area("Enter your text here:")
|
26 |
|
27 |
-
#
|
28 |
-
if
|
29 |
-
|
30 |
-
st.warning("Please enter some text.")
|
31 |
-
else:
|
32 |
-
message = analyze_sentiment(user_input)
|
33 |
-
st.success(message)
|
|
|
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 |
|
|
|
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()
|
|
|
|
|
|
|
|