Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,6 @@ import os
|
|
2 |
import gradio as gr
|
3 |
import nltk
|
4 |
import numpy as np
|
5 |
-
import tflearn
|
6 |
-
import random
|
7 |
import json
|
8 |
import pickle
|
9 |
from nltk.tokenize import word_tokenize
|
@@ -13,7 +11,8 @@ import googlemaps
|
|
13 |
import folium
|
14 |
import torch
|
15 |
import pandas as pd
|
16 |
-
from
|
|
|
17 |
from sklearn.ensemble import RandomForestClassifier
|
18 |
from sklearn.naive_bayes import GaussianNB
|
19 |
from sklearn.metrics import accuracy_score
|
@@ -34,14 +33,20 @@ with open("intents.json") as file:
|
|
34 |
with open("data.pickle", "rb") as f:
|
35 |
words, labels, training, output = pickle.load(f)
|
36 |
|
37 |
-
# Build the chatbot model
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
# Hugging Face sentiment and emotion models
|
47 |
tokenizer_sentiment = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
|
@@ -90,7 +95,7 @@ def load_data():
|
|
90 |
'Tuberculosis': 25,
|
91 |
'Common Cold': 26,
|
92 |
'Pneumonia': 27,
|
93 |
-
'Dimorphic hemorrhoids (piles)': 28,
|
94 |
'Heart attack': 29,
|
95 |
'Varicose veins': 30,
|
96 |
'Hypothyroidism': 31,
|
@@ -108,7 +113,7 @@ def load_data():
|
|
108 |
# Replace prognosis values with numerical categories
|
109 |
df.replace({'prognosis': disease_dict}, inplace=True)
|
110 |
|
111 |
-
# Check unique values in prognosis
|
112 |
print("Unique values in prognosis after mapping:", df['prognosis'].unique())
|
113 |
|
114 |
# Ensure prognosis is purely numerical after mapping
|
@@ -358,7 +363,7 @@ with gr.Blocks() as app:
|
|
358 |
chatbot = gr.Chatbot(label="Chat History")
|
359 |
sentiment = gr.Textbox(label="Detected Sentiment")
|
360 |
emotion = gr.Textbox(label="Detected Emotion")
|
361 |
-
|
362 |
suggestions = gr.DataFrame(headers=["Title", "Link"])
|
363 |
professionals = gr.DataFrame(label="Nearby Health Professionals", headers=["Name", "Address"])
|
364 |
map_html = gr.HTML(label="Interactive Map")
|
|
|
2 |
import gradio as gr
|
3 |
import nltk
|
4 |
import numpy as np
|
|
|
|
|
5 |
import json
|
6 |
import pickle
|
7 |
from nltk.tokenize import word_tokenize
|
|
|
11 |
import folium
|
12 |
import torch
|
13 |
import pandas as pd
|
14 |
+
from tensorflow import keras
|
15 |
+
from tensorflow.keras import layers
|
16 |
from sklearn.ensemble import RandomForestClassifier
|
17 |
from sklearn.naive_bayes import GaussianNB
|
18 |
from sklearn.metrics import accuracy_score
|
|
|
33 |
with open("data.pickle", "rb") as f:
|
34 |
words, labels, training, output = pickle.load(f)
|
35 |
|
36 |
+
# Build the chatbot model using Keras
|
37 |
+
def build_chatbot_model(input_shape, output_shape):
|
38 |
+
model = keras.Sequential()
|
39 |
+
model.add(layers.Input(shape=(input_shape,)))
|
40 |
+
model.add(layers.Dense(8, activation='relu'))
|
41 |
+
model.add(layers.Dense(8, activation='relu'))
|
42 |
+
model.add(layers.Dense(output_shape, activation='softmax'))
|
43 |
+
|
44 |
+
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
|
45 |
+
return model
|
46 |
+
|
47 |
+
# Build and train the chatbot model
|
48 |
+
chatbot_model = build_chatbot_model(len(training[0]), len(output[0]))
|
49 |
+
chatbot_model.fit(training, output, epochs=100) # Adjust epochs and model fitting parameters as necessary
|
50 |
|
51 |
# Hugging Face sentiment and emotion models
|
52 |
tokenizer_sentiment = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
|
|
|
95 |
'Tuberculosis': 25,
|
96 |
'Common Cold': 26,
|
97 |
'Pneumonia': 27,
|
98 |
+
'Dimorphic hemorrhoids (piles)': 28,
|
99 |
'Heart attack': 29,
|
100 |
'Varicose veins': 30,
|
101 |
'Hypothyroidism': 31,
|
|
|
113 |
# Replace prognosis values with numerical categories
|
114 |
df.replace({'prognosis': disease_dict}, inplace=True)
|
115 |
|
116 |
+
# Check unique values in prognosis after mapping
|
117 |
print("Unique values in prognosis after mapping:", df['prognosis'].unique())
|
118 |
|
119 |
# Ensure prognosis is purely numerical after mapping
|
|
|
363 |
chatbot = gr.Chatbot(label="Chat History")
|
364 |
sentiment = gr.Textbox(label="Detected Sentiment")
|
365 |
emotion = gr.Textbox(label="Detected Emotion")
|
366 |
+
|
367 |
suggestions = gr.DataFrame(headers=["Title", "Link"])
|
368 |
professionals = gr.DataFrame(label="Nearby Health Professionals", headers=["Name", "Address"])
|
369 |
map_html = gr.HTML(label="Interactive Map")
|