Spaces:
Build error
Build error
rishabh5752
commited on
Commit
•
0a9270c
1
Parent(s):
ccde68c
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,11 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
# coding: utf-8
|
3 |
-
|
4 |
-
# In[ ]:
|
5 |
-
|
6 |
-
|
7 |
import streamlit as st
|
8 |
import nltk
|
9 |
-
from nltk.stem import WordNetLemmatizer
|
10 |
import pickle
|
11 |
import numpy as np
|
12 |
from tensorflow.keras.models import load_model
|
|
|
13 |
|
14 |
-
|
15 |
-
nltk.download('wordnet')
|
16 |
-
|
17 |
-
# Load saved model and other necessary files
|
18 |
model = load_model("chatbot_model.h5")
|
19 |
words = pickle.load(open('words.pkl', 'rb'))
|
20 |
classes = pickle.load(open('classes.pkl', 'rb'))
|
@@ -40,28 +31,24 @@ def bow(sentence, words, show_details=True):
|
|
40 |
|
41 |
# Streamlit app
|
42 |
def main():
|
43 |
-
st.title("Chatbot
|
44 |
-
st.write("Welcome to the
|
45 |
|
46 |
-
user_input = st.text_input("You:
|
47 |
-
if st.button("
|
48 |
if user_input.strip() == "":
|
49 |
-
st.write("Bot: Please enter
|
50 |
else:
|
51 |
p = bow(user_input, words)
|
52 |
res = model.predict(np.array([p]))[0]
|
53 |
ERROR_THRESHOLD = 0.25
|
54 |
results = [[i, r] for i, r in enumerate(res) if r > ERROR_THRESHOLD]
|
55 |
results.sort(key=lambda x: x[1], reverse=True)
|
56 |
-
return_list = []
|
57 |
for r in results:
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
break
|
63 |
-
st.write("Bot:", response)
|
64 |
|
65 |
if __name__ == "__main__":
|
66 |
main()
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import nltk
|
|
|
3 |
import pickle
|
4 |
import numpy as np
|
5 |
from tensorflow.keras.models import load_model
|
6 |
+
from nltk.stem import WordNetLemmatizer
|
7 |
|
8 |
+
# Load the pre-trained model and other data
|
|
|
|
|
|
|
9 |
model = load_model("chatbot_model.h5")
|
10 |
words = pickle.load(open('words.pkl', 'rb'))
|
11 |
classes = pickle.load(open('classes.pkl', 'rb'))
|
|
|
31 |
|
32 |
# Streamlit app
|
33 |
def main():
|
34 |
+
st.title("Healthcare Chatbot")
|
35 |
+
st.write("Welcome to the Healthcare Chatbot! Enter your symptoms below.")
|
36 |
|
37 |
+
user_input = st.text_input("You:")
|
38 |
+
if st.button("Predict"):
|
39 |
if user_input.strip() == "":
|
40 |
+
st.write("Bot: Please enter your symptoms.")
|
41 |
else:
|
42 |
p = bow(user_input, words)
|
43 |
res = model.predict(np.array([p]))[0]
|
44 |
ERROR_THRESHOLD = 0.25
|
45 |
results = [[i, r] for i, r in enumerate(res) if r > ERROR_THRESHOLD]
|
46 |
results.sort(key=lambda x: x[1], reverse=True)
|
|
|
47 |
for r in results:
|
48 |
+
return_class = classes[r[0]]
|
49 |
+
break
|
50 |
+
|
51 |
+
st.write("Bot: Based on your symptoms, you might have:", return_class)
|
|
|
|
|
52 |
|
53 |
if __name__ == "__main__":
|
54 |
main()
|
|