tahirsher commited on
Commit
f9f5c08
·
verified ·
1 Parent(s): 2c7367f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -64
app.py CHANGED
@@ -1,6 +1,4 @@
1
  import nltk
2
- nltk.download('punkt')
3
- from nltk.stem.lancaster import LancasterStemmer
4
  import numpy as np
5
  import tflearn
6
  import tensorflow
@@ -9,12 +7,10 @@ import json
9
  import pickle
10
  import gradio as gr
11
  from nltk.tokenize import word_tokenize
 
12
 
13
  # Ensure necessary NLTK resources are downloaded
14
- try:
15
- nltk.data.find('tokenizers/punkt')
16
- except LookupError:
17
- nltk.download('punkt')
18
 
19
  # Initialize the stemmer
20
  stemmer = LancasterStemmer()
@@ -45,12 +41,12 @@ model = tflearn.DNN(net)
45
  try:
46
  model.load("MentalHealthChatBotmodel.tflearn")
47
  except FileNotFoundError:
48
- print("Error: Trained model file not found. Ensure 'MentalHealthChatBotmodel.tflearn' exists.")
49
 
50
  # Function to process user input into a bag-of-words format
51
  def bag_of_words(s, words):
52
  bag = [0 for _ in range(len(words))]
53
- s_words = word_tokenize(s) # Replaced nltk.word_tokenize(s)
54
  s_words = [stemmer.stem(word.lower()) for word in s_words if word.lower() in words]
55
  for se in s_words:
56
  for i, w in enumerate(words):
@@ -86,67 +82,12 @@ def chat(message, history):
86
 
87
  # Gradio interface
88
  chatbot = gr.Chatbot(label="Chat")
89
- css = """
90
- footer {display:none !important}
91
- .output-markdown{display:none !important}
92
- .gr-button-primary {
93
- z-index: 14;
94
- height: 43px;
95
- width: 130px;
96
- left: 0px;
97
- top: 0px;
98
- padding: 0px;
99
- cursor: pointer !important;
100
- background: none rgb(17, 20, 45) !important;
101
- border: none !important;
102
- text-align: center !important;
103
- font-family: Poppins !important;
104
- font-size: 14px !important;
105
- font-weight: 500 !important;
106
- color: rgb(255, 255, 255) !important;
107
- line-height: 1 !important;
108
- border-radius: 12px !important;
109
- transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
110
- box-shadow: none !important;
111
- }
112
- .gr-button-primary:hover{
113
- z-index: 14;
114
- height: 43px;
115
- width: 130px;
116
- left: 0px;
117
- top: 0px;
118
- padding: 0px;
119
- cursor: pointer !important;
120
- background: none rgb(37, 56, 133) !important;
121
- border: none !important;
122
- text-align: center !important;
123
- font-family: Poppins !important;
124
- font-size: 14px !important;
125
- font-weight: 500 !important;
126
- color: rgb(255, 255, 255) !important;
127
- line-height: 1 !important;
128
- border-radius: 12px !important;
129
- transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
130
- box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;
131
- }
132
- .hover\:bg-orange-50:hover {
133
- --tw-bg-opacity: 1 !important;
134
- background-color: rgb(229,225,255) !important;
135
- }
136
- div[data-testid="user"] {
137
- background-color: #253885 !important;
138
- }
139
- .h-\[40vh\]{
140
- height: 70vh !important;
141
- }
142
- """
143
  demo = gr.Interface(
144
  chat,
145
  [gr.Textbox(lines=1, label="Message"), "state"],
146
  [chatbot, "state"],
147
  allow_flagging="never",
148
- title="Mental Health Bot | Data Science Dojo",
149
- css=css
150
  )
151
 
152
  # Launch Gradio interface
 
1
  import nltk
 
 
2
  import numpy as np
3
  import tflearn
4
  import tensorflow
 
7
  import pickle
8
  import gradio as gr
9
  from nltk.tokenize import word_tokenize
10
+ from nltk.stem.lancaster import LancasterStemmer
11
 
12
  # Ensure necessary NLTK resources are downloaded
13
+ nltk.download('punkt')
 
 
 
14
 
15
  # Initialize the stemmer
16
  stemmer = LancasterStemmer()
 
41
  try:
42
  model.load("MentalHealthChatBotmodel.tflearn")
43
  except FileNotFoundError:
44
+ raise FileNotFoundError("Error: Trained model file 'MentalHealthChatBotmodel.tflearn' not found.")
45
 
46
  # Function to process user input into a bag-of-words format
47
  def bag_of_words(s, words):
48
  bag = [0 for _ in range(len(words))]
49
+ s_words = word_tokenize(s)
50
  s_words = [stemmer.stem(word.lower()) for word in s_words if word.lower() in words]
51
  for se in s_words:
52
  for i, w in enumerate(words):
 
82
 
83
  # Gradio interface
84
  chatbot = gr.Chatbot(label="Chat")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  demo = gr.Interface(
86
  chat,
87
  [gr.Textbox(lines=1, label="Message"), "state"],
88
  [chatbot, "state"],
89
  allow_flagging="never",
90
+ title="Wellbeing for All, ** I am your Best Friend **",
 
91
  )
92
 
93
  # Launch Gradio interface