DreamStream-1 commited on
Commit
11f26d3
·
verified ·
1 Parent(s): c928c06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -108,8 +108,13 @@ def chat(message, history, state):
108
  tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
109
  sentiment_model = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
110
 
 
111
  # Function for sentiment analysis
112
  def analyze_sentiment(text, state):
 
 
 
 
113
  inputs = tokenizer(text, return_tensors="pt")
114
  with torch.no_grad():
115
  outputs = sentiment_model(**inputs)
@@ -224,9 +229,10 @@ def get_all_places(query, location, radius, api_key):
224
  return []
225
 
226
  # Gradio UI components
 
227
  def create_ui():
228
  with gr.Blocks() as demo:
229
- state = gr.State()
230
  chatbot = gr.Chatbot(elem_id="chatbot", label="Mental Health Chatbot")
231
  message_input = gr.Textbox(placeholder="Ask me something...", label="Enter your message")
232
  sentiment_output = gr.Textbox(placeholder="Sentiment result", label="Sentiment")
 
108
  tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
109
  sentiment_model = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
110
 
111
+ # Function for sentiment analysis
112
  # Function for sentiment analysis
113
  def analyze_sentiment(text, state):
114
+ # Initialize state if it's None
115
+ if state is None:
116
+ state = {'step': 1}
117
+
118
  inputs = tokenizer(text, return_tensors="pt")
119
  with torch.no_grad():
120
  outputs = sentiment_model(**inputs)
 
229
  return []
230
 
231
  # Gradio UI components
232
+ # Function to create the UI with state initialization
233
  def create_ui():
234
  with gr.Blocks() as demo:
235
+ state = gr.State({'step': 1}) # Initialize state with a default value
236
  chatbot = gr.Chatbot(elem_id="chatbot", label="Mental Health Chatbot")
237
  message_input = gr.Textbox(placeholder="Ask me something...", label="Enter your message")
238
  sentiment_output = gr.Textbox(placeholder="Sentiment result", label="Sentiment")