Update app.py
Browse files
app.py
CHANGED
@@ -155,35 +155,31 @@ def generate(prompt, history):
|
|
155 |
global isFirstRun,initContext,Name,Occupation,Ethnicity,Gender,Age
|
156 |
|
157 |
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:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
-
firstmsg =""
|
160 |
-
if not isFirstRun:
|
161 |
-
formatted_prompt = format_prompt(prompt, history)
|
162 |
-
else:
|
163 |
-
firstmsg = prompt
|
164 |
-
initContext += prompt
|
165 |
-
prompt = initContext
|
166 |
-
formatted_prompt=format_prompt(initContext,history)
|
167 |
-
print("init Context added")
|
168 |
-
print(f"\n THE PROMPT IS,\n {formatted_prompt} \n PROMPT END")
|
169 |
-
|
170 |
-
stream = client.text_generation(formatted_prompt, max_new_tokens = 2048,repetition_penalty = 1.4,temperature = 0.8,stream=True, details=True, return_full_text=False )
|
171 |
-
output = ""
|
172 |
-
|
173 |
-
#print(chat_history)
|
174 |
-
for response in stream:
|
175 |
-
output += response.token.text
|
176 |
-
yield output
|
177 |
-
|
178 |
-
output = strip_special_tokens(output)
|
179 |
-
chat_history.append([prompt, output])
|
180 |
-
if not isFirstRun:
|
181 |
-
chat_log_history.append({"user": prompt, "bot": output})
|
182 |
-
upload_to_google_drive()
|
183 |
-
else:
|
184 |
-
chat_log_history.append({"user": firstmsg, "bot": output})
|
185 |
-
|
186 |
-
return output
|
187 |
else:
|
188 |
output = "Did you forget to enter your Details? Please go to the User Info Tab and Input your data. "
|
189 |
yield output
|
|
|
155 |
global isFirstRun,initContext,Name,Occupation,Ethnicity,Gender,Age
|
156 |
|
157 |
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:
|
158 |
+
|
159 |
+
if isFirstRun:
|
160 |
+
context = initContext
|
161 |
+
isFirstRun = False
|
162 |
+
|
163 |
+
context += """
|
164 |
+
<|im_start|>nurse
|
165 |
+
Nurse: """+prompt+"""
|
166 |
+
<|im_start|>barry
|
167 |
+
Barry:
|
168 |
+
"""
|
169 |
+
|
170 |
+
response = ""
|
171 |
+
|
172 |
+
while(len(response) < 1):
|
173 |
+
output = llm(context, max_tokens=400, stop=["Nurse:"], echo=False)
|
174 |
+
response = output["choices"][0]["text"]
|
175 |
+
response = response.strip()
|
176 |
+
|
177 |
+
context += response
|
178 |
+
print (output)
|
179 |
+
|
180 |
+
history.append((prompt,response))
|
181 |
+
yield response
|
182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
else:
|
184 |
output = "Did you forget to enter your Details? Please go to the User Info Tab and Input your data. "
|
185 |
yield output
|