Madiharehan commited on
Commit
6db8709
β€’
1 Parent(s): 3e75920

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -1,8 +1,7 @@
1
- import streamlit as st
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
- # Streamlit UI
21
- st.title("Student Sentiment Analysis Chatbot")
22
- st.write("This chatbot detects your mood and provides positive or motivational messages.")
 
 
 
 
 
 
 
23
 
24
- # User input section
25
- user_input = st.text_area("Enter your text here:")
26
 
27
- # Button to analyze sentiment
28
- if st.button("Analyze Sentiment"):
29
- if user_input.strip() == "":
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()