DreamStream-1 commited on
Commit
5f4fda6
Β·
verified Β·
1 Parent(s): 1949203

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -31
app.py CHANGED
@@ -39,18 +39,18 @@ net = tflearn.regression(net)
39
  chatbot_model = tflearn.DNN(net)
40
  chatbot_model.load("MentalHealthChatBotmodel.tflearn")
41
 
42
- # Sentiment Analysis with Hugging Face
43
  tokenizer_sentiment = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
44
  model_sentiment = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
45
 
46
- # Emotion Detection
47
  tokenizer_emotion = AutoTokenizer.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
48
  model_emotion = AutoModelForSequenceClassification.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
49
 
50
- # Google Maps API Client
51
  gmaps = googlemaps.Client(key=os.getenv('GOOGLE_API_KEY'))
52
 
53
- # Chatbot Logic
54
  def bag_of_words(s, words):
55
  bag = [0] * len(words)
56
  s_words = word_tokenize(s)
@@ -77,7 +77,7 @@ def chatbot(message, history):
77
  history.append((message, response))
78
  return history, response
79
 
80
- # Sentiment Analysis
81
  def analyze_sentiment(user_input):
82
  inputs = tokenizer_sentiment(user_input, return_tensors="pt")
83
  with torch.no_grad():
@@ -86,7 +86,7 @@ def analyze_sentiment(user_input):
86
  sentiment_map = ["Negative πŸ˜”", "Neutral 😐", "Positive 😊"]
87
  return sentiment_map[sentiment_class]
88
 
89
- # Emotion Detection
90
  def detect_emotion(user_input):
91
  pipe = pipeline("text-classification", model=model_emotion, tokenizer=tokenizer_emotion)
92
  result = pipe(user_input)
@@ -139,14 +139,13 @@ def app_function(message, location, query, history):
139
  professionals, map_html = get_health_professionals_and_map(location, query)
140
  return chatbot_history, sentiment, emotion, suggestions, professionals, map_html
141
 
142
- # Enhanced CSS for Black-Themed Table and UI
143
  custom_css = """
144
  @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
145
  body {
146
  background: linear-gradient(135deg, #000000, #ff5722);
147
  color: white;
148
  font-family: 'Roboto', sans-serif;
149
- text-align: center;
150
  }
151
  button {
152
  background-color: #ff5722 !important;
@@ -156,7 +155,6 @@ button {
156
  font-size: 16px;
157
  border-radius: 8px;
158
  cursor: pointer;
159
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
160
  }
161
  button:hover {
162
  background-color: #e64a19 !important;
@@ -169,29 +167,25 @@ textarea, input[type="text"], .gr-chatbot {
169
  border-radius: 8px !important;
170
  font-size: 14px;
171
  }
172
- .gr-textbox {
173
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
174
- }
175
- .output-container, .gr-html, .gr-textbox, .gr-dataframe {
176
  background: #000000 !important;
177
  color: white !important;
178
  border: 2px solid #ff5722 !important;
179
  border-radius: 8px !important;
180
- padding: 10px;
181
- }
182
- .gr-dataframe {
183
  font-size: 14px;
184
- height: 400px; /* Larger table */
185
- overflow-y: scroll; /* Scroll if content exceeds table height */
186
- background: #000000 !important;
187
- color: white !important;
188
- border: 2px solid #ff5722;
 
189
  }
190
  h1 {
191
- font-size: 3.5rem;
192
  font-weight: bold;
193
  margin-bottom: 10px;
194
  color: white;
 
195
  text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.6);
196
  }
197
  h2 {
@@ -200,6 +194,12 @@ h2 {
200
  color: white;
201
  text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.4);
202
  }
 
 
 
 
 
 
203
  """
204
 
205
  # Gradio Interface
@@ -208,17 +208,26 @@ with gr.Blocks(css=custom_css) as app:
208
  gr.HTML("<h2>Empowering Your Well-Being Journey πŸ’š</h2>")
209
 
210
  with gr.Row():
211
- user_message = gr.Textbox(label="Your Message", placeholder="Enter your message...")
212
- user_location = gr.Textbox(label="Your Location", placeholder="Enter your location...")
213
- search_query = gr.Textbox(label="Query", placeholder="Search for professionals...")
214
- submit_btn = gr.Button("Submit")
 
 
215
 
216
  chatbot_box = gr.Chatbot(label="Chat History")
217
- emotion_output = gr.Textbox(label="Detected Emotion")
218
- sentiment_output = gr.Textbox(label="Detected Sentiment")
219
- suggestions_output = gr.DataFrame(headers=["Title", "Links"], label="Suggestions") # Enlarged table
220
- map_output = gr.HTML(label="Nearby Professionals Map")
221
- professional_display = gr.Textbox(label="Nearby Professionals", lines=5)
 
 
 
 
 
 
 
222
 
223
  submit_btn.click(
224
  app_function,
 
39
  chatbot_model = tflearn.DNN(net)
40
  chatbot_model.load("MentalHealthChatBotmodel.tflearn")
41
 
42
+ # Model for sentiment detection
43
  tokenizer_sentiment = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
44
  model_sentiment = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
45
 
46
+ # Model for emotion detection
47
  tokenizer_emotion = AutoTokenizer.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
48
  model_emotion = AutoModelForSequenceClassification.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
49
 
50
+ # Google Maps API client
51
  gmaps = googlemaps.Client(key=os.getenv('GOOGLE_API_KEY'))
52
 
53
+ # Chatbot logic
54
  def bag_of_words(s, words):
55
  bag = [0] * len(words)
56
  s_words = word_tokenize(s)
 
77
  history.append((message, response))
78
  return history, response
79
 
80
+ # Sentiment analysis
81
  def analyze_sentiment(user_input):
82
  inputs = tokenizer_sentiment(user_input, return_tensors="pt")
83
  with torch.no_grad():
 
86
  sentiment_map = ["Negative πŸ˜”", "Neutral 😐", "Positive 😊"]
87
  return sentiment_map[sentiment_class]
88
 
89
+ # Emotion detection
90
  def detect_emotion(user_input):
91
  pipe = pipeline("text-classification", model=model_emotion, tokenizer=tokenizer_emotion)
92
  result = pipe(user_input)
 
139
  professionals, map_html = get_health_professionals_and_map(location, query)
140
  return chatbot_history, sentiment, emotion, suggestions, professionals, map_html
141
 
142
+ # Enhanced CSS for Custom Title and Styling
143
  custom_css = """
144
  @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
145
  body {
146
  background: linear-gradient(135deg, #000000, #ff5722);
147
  color: white;
148
  font-family: 'Roboto', sans-serif;
 
149
  }
150
  button {
151
  background-color: #ff5722 !important;
 
155
  font-size: 16px;
156
  border-radius: 8px;
157
  cursor: pointer;
 
158
  }
159
  button:hover {
160
  background-color: #e64a19 !important;
 
167
  border-radius: 8px !important;
168
  font-size: 14px;
169
  }
170
+ .gr-dataframe, .gr-textbox {
 
 
 
171
  background: #000000 !important;
172
  color: white !important;
173
  border: 2px solid #ff5722 !important;
174
  border-radius: 8px !important;
 
 
 
175
  font-size: 14px;
176
+ }
177
+ .suggestions-title {
178
+ font-size: 1.5rem !important;
179
+ font-weight: bold;
180
+ color: white;
181
+ margin-top: 20px;
182
  }
183
  h1 {
184
+ font-size: 4rem;
185
  font-weight: bold;
186
  margin-bottom: 10px;
187
  color: white;
188
+ text-align: center;
189
  text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.6);
190
  }
191
  h2 {
 
194
  color: white;
195
  text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.4);
196
  }
197
+ .input-title, .output-title {
198
+ font-size: 1.5rem;
199
+ font-weight: bold;
200
+ color: black;
201
+ margin-bottom: 10px;
202
+ }
203
  """
204
 
205
  # Gradio Interface
 
208
  gr.HTML("<h2>Empowering Your Well-Being Journey πŸ’š</h2>")
209
 
210
  with gr.Row():
211
+ gr.Markdown("<div class='input-title'>Your Message</div>")
212
+ user_message = gr.Textbox(label=None, placeholder="Enter your message...")
213
+ gr.Markdown("<div class='input-title'>Your Location</div>")
214
+ user_location = gr.Textbox(label=None, placeholder="Enter your location...")
215
+ gr.Markdown("<div class='input-title'>Your Query</div>")
216
+ search_query = gr.Textbox(label=None, placeholder="Search for professionals...")
217
 
218
  chatbot_box = gr.Chatbot(label="Chat History")
219
+ gr.Markdown("<div class='output-title'>Detected Emotion</div>")
220
+ emotion_output = gr.Textbox(label=None)
221
+ gr.Markdown("<div class='output-title'>Detected Sentiment</div>")
222
+ sentiment_output = gr.Textbox(label=None)
223
+ gr.Markdown("<div class='suggestions-title'>Suggestions</div>")
224
+ suggestions_output = gr.DataFrame(headers=["Title", "Links"], label=None)
225
+
226
+ gr.Markdown("<h2 class='suggestions-title'>Health Professionals Nearby</h2>")
227
+ map_output = gr.HTML(label=None)
228
+ professional_display = gr.Textbox(label=None, lines=5)
229
+
230
+ submit_btn = gr.Button("Submit")
231
 
232
  submit_btn.click(
233
  app_function,