Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import nltk
|
| 3 |
import numpy as np
|
|
@@ -11,10 +12,12 @@ from nltk.stem.lancaster import LancasterStemmer
|
|
| 11 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 12 |
import googlemaps
|
| 13 |
import folium
|
| 14 |
-
import os
|
| 15 |
import pandas as pd
|
| 16 |
import torch
|
| 17 |
|
|
|
|
|
|
|
|
|
|
| 18 |
# Ensure necessary NLTK resources are downloaded
|
| 19 |
nltk.download('punkt')
|
| 20 |
|
|
@@ -206,22 +209,24 @@ def gradio_app(message, location, health_query, submit_button, history, state):
|
|
| 206 |
message_input = gr.Textbox(lines=1, label="Message")
|
| 207 |
location_input = gr.Textbox(value="Honolulu, HI", label="Current Location")
|
| 208 |
health_query_input = gr.Textbox(value="doctor", label="Health Professional Query (e.g., doctor, psychiatrist, psychologist)")
|
| 209 |
-
submit_button = gr.Button("Submit") # Submit button
|
| 210 |
|
| 211 |
-
|
|
|
|
| 212 |
|
| 213 |
# Outputs
|
| 214 |
sentiment_output = gr.Textbox(label="Sentiment Analysis Result")
|
| 215 |
emotion_output = gr.Textbox(label="Emotion Detection Result")
|
| 216 |
route_info_output = gr.Textbox(label="Health Professionals Information")
|
| 217 |
map_output = gr.HTML(label="Map with Health Professionals")
|
| 218 |
-
suggestions_output = gr.DataFrame(label="Well-Being Suggestions", headers=["Title", "Subject", "Link"])
|
| 219 |
|
| 220 |
# Create Gradio interface
|
|
|
|
| 221 |
iface = gr.Interface(
|
| 222 |
fn=gradio_app,
|
| 223 |
-
inputs=[message_input, location_input, health_query_input, submit_button, gr.State()
|
| 224 |
-
outputs=[chat_history, sentiment_output, emotion_output, route_info_output, map_output, suggestions_output, gr.State()], #
|
| 225 |
allow_flagging="never",
|
| 226 |
live=True,
|
| 227 |
title="Well-Being App: Support, Sentiment, Emotion Detection & Health Professional Search"
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
import nltk
|
| 4 |
import numpy as np
|
|
|
|
| 12 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 13 |
import googlemaps
|
| 14 |
import folium
|
|
|
|
| 15 |
import pandas as pd
|
| 16 |
import torch
|
| 17 |
|
| 18 |
+
# Disable GPU usage for TensorFlow
|
| 19 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
|
| 20 |
+
|
| 21 |
# Ensure necessary NLTK resources are downloaded
|
| 22 |
nltk.download('punkt')
|
| 23 |
|
|
|
|
| 209 |
message_input = gr.Textbox(lines=1, label="Message")
|
| 210 |
location_input = gr.Textbox(value="Honolulu, HI", label="Current Location")
|
| 211 |
health_query_input = gr.Textbox(value="doctor", label="Health Professional Query (e.g., doctor, psychiatrist, psychologist)")
|
| 212 |
+
submit_button = gr.Button("Submit") # Submit button
|
| 213 |
|
| 214 |
+
# Updated chat history component with 'messages' type
|
| 215 |
+
chat_history = gr.Chatbot(label="Well-Being Chat History", type='messages')
|
| 216 |
|
| 217 |
# Outputs
|
| 218 |
sentiment_output = gr.Textbox(label="Sentiment Analysis Result")
|
| 219 |
emotion_output = gr.Textbox(label="Emotion Detection Result")
|
| 220 |
route_info_output = gr.Textbox(label="Health Professionals Information")
|
| 221 |
map_output = gr.HTML(label="Map with Health Professionals")
|
| 222 |
+
suggestions_output = gr.DataFrame(label="Well-Being Suggestions", headers=["Title", "Subject", "Link"])
|
| 223 |
|
| 224 |
# Create Gradio interface
|
| 225 |
+
# Ensure there is exactly one state input and one state output
|
| 226 |
iface = gr.Interface(
|
| 227 |
fn=gradio_app,
|
| 228 |
+
inputs=[message_input, location_input, health_query_input, submit_button, gr.State()], # Updated to include only one state input
|
| 229 |
+
outputs=[chat_history, sentiment_output, emotion_output, route_info_output, map_output, suggestions_output, gr.State()], # Updated to include only one state output
|
| 230 |
allow_flagging="never",
|
| 231 |
live=True,
|
| 232 |
title="Well-Being App: Support, Sentiment, Emotion Detection & Health Professional Search"
|