ECUiVADE commited on
Commit
09ed43d
1 Parent(s): 627b943

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -43
app.py CHANGED
@@ -12,7 +12,6 @@ import argparse
12
  from huggingface_hub import snapshot_download
13
  import random
14
  import string
15
- import time
16
 
17
  #TODO : Cleanup and comment
18
 
@@ -151,36 +150,57 @@ def upload_to_google_drive():
151
 
152
 
153
  def generate(prompt, history):
154
- global isFirstRun, initContext, Name, Occupation, Ethnicity, Gender, Age, context, YearsOfExp, agreed
 
 
 
155
  if agreed:
156
- firstmsg = ""
157
  if isFirstRun:
158
  context = initContext
159
  isFirstRun = False
160
  firstmsg = prompt
161
-
162
- context += f"""
163
- Nurse:{prompt}
164
- Barry:
165
- """
166
-
 
 
 
167
  response = ""
 
 
168
  while(len(response) < 1):
169
  output = llm(context, max_tokens=400, stop=["Nurse:"], echo=False)
170
- response = output["choices"][0]["text"].strip()
 
 
 
171
 
172
- history.append((prompt, response))
173
- if not isFirstRun:
 
 
 
 
 
 
 
174
  chat_log_history.append({"user": prompt, "bot": response})
 
175
  else:
176
- chat_log_history.append({"user": firstmsg, "bot": response})
177
-
178
  context += response
179
 
180
- return history
 
 
181
  else:
182
- output = "Did you forget to enter your Details? Please go to the User Info Tab and Input your data."
183
- return [(prompt, output)] # Ensure this is formatted as a list of tuples
184
 
185
  def submit_user_info(name,occupation,yearsofexp,ethnicity,gender,age):
186
  global Name, Occupation,Ethnicity,Gender,Age,chat_log_name,YearsOfExp
@@ -225,19 +245,6 @@ def reset_name_interface():
225
  chat_log_name = ""
226
  return "User info has been reset."
227
 
228
-
229
- def add_text(history, text):
230
- history = history + [(text, None)]
231
- return history, gr.Textbox(value="", interactive=False)
232
-
233
- def bot(history):
234
- response = "**That's cool!**"
235
- history[-1][1] = ""
236
- for character in response:
237
- history[-1][1] += character
238
- time.sleep(0.05)
239
- yield history
240
-
241
  def reset_all():
242
  global unique_id
243
  message1 = reset_chat_interface()
@@ -279,19 +286,12 @@ with gr.Blocks() as app:
279
 
280
 
281
  with gr.Tab("Chat Bot"):
282
- chatbot = gr.Chatbot([],elem_id="chatbot",bubble_full_width=False,)
283
- with gr.Row():
284
-
285
- txt = gr.Textbox(
286
- scale=4,
287
- show_label=False,
288
- placeholder="Enter text and press enter, or upload an image",
289
- container=False,)
290
-
291
- txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
292
- generate, chatbot, chatbot, api_name="bot_response"
293
- )
294
- txt_msg.then(lambda: gr.Textbox(interactive=True), None, [txt], queue=False)
295
 
296
  with gr.Tab("Reset"):
297
  reset_button = gr.Button("Reset ChatBot Instance")
 
12
  from huggingface_hub import snapshot_download
13
  import random
14
  import string
 
15
 
16
  #TODO : Cleanup and comment
17
 
 
150
 
151
 
152
  def generate(prompt, history):
153
+
154
+ global isFirstRun,initContext,Name,Occupation,Ethnicity,Gender,Age,context,YearsOfExp
155
+
156
+ #if not len(Name) == 0 and not len(Occupation) == 0 and not len(Ethnicity) == 0 and not len(Gender) == 0 and not len(Age) == 0 and not len(YearsOfExp):
157
  if agreed:
158
+ firstmsg =""
159
  if isFirstRun:
160
  context = initContext
161
  isFirstRun = False
162
  firstmsg = prompt
163
+
164
+
165
+ context += """
166
+ <|im_start|>nurse
167
+ Nurse:"""+prompt+"""
168
+ <|im_start|>barry
169
+ Barry:
170
+ """
171
+
172
  response = ""
173
+ history2 = []
174
+
175
  while(len(response) < 1):
176
  output = llm(context, max_tokens=400, stop=["Nurse:"], echo=False)
177
+ response = output["choices"][0]["text"]
178
+ response = response.strip()
179
+ #yield response
180
+
181
 
182
+ # for output in llm(input, stream=True, max_tokens=100, ):
183
+ # piece = output['choices'][0]['text']
184
+ # response += piece
185
+ # chatbot[-1] = (chatbot[-1][0], response)
186
+
187
+ # yield response
188
+
189
+ history.append((prompt,response))
190
+ if not isFirstRun:
191
  chat_log_history.append({"user": prompt, "bot": response})
192
+ upload_to_google_drive()
193
  else:
194
+ chat_log_history.append({"user": firstmsg, "bot": reponse})
195
+
196
  context += response
197
 
198
+ print (context)
199
+ return "", history
200
+
201
  else:
202
+ output = "Did you forget to enter your Details? Please go to the User Info Tab and Input your data. "
203
+ return output
204
 
205
  def submit_user_info(name,occupation,yearsofexp,ethnicity,gender,age):
206
  global Name, Occupation,Ethnicity,Gender,Age,chat_log_name,YearsOfExp
 
245
  chat_log_name = ""
246
  return "User info has been reset."
247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  def reset_all():
249
  global unique_id
250
  message1 = reset_chat_interface()
 
286
 
287
 
288
  with gr.Tab("Chat Bot"):
289
+ chatbot = gr.Chatbot()
290
+ msg = gr.Textbox(label="Type your message")
291
+ send = gr.Button("Send")
292
+ clear = gr.Button("Clear Chat")
293
+ send.click(generate, inputs=[msg], outputs=chatbot)
294
+ clear.click(lambda: chatbot.clear(), inputs=[], outputs=chatbot)
 
 
 
 
 
 
 
295
 
296
  with gr.Tab("Reset"):
297
  reset_button = gr.Button("Reset ChatBot Instance")