Spaces:
Runtime error
Runtime error
removed logging
Browse files
app.py
CHANGED
@@ -16,27 +16,17 @@ css = """.toast-wrap { display: none !important } """
|
|
16 |
|
17 |
def predict(message, chatbot):
|
18 |
|
19 |
-
print(f"Logging: message is - {message}")
|
20 |
-
print(f"Logging: chatbot is - {chatbot}")
|
21 |
-
|
22 |
input_prompt = f"[INST]<<SYS>>\n{system_message}\n<</SYS>>\n\n "
|
23 |
for interaction in chatbot:
|
24 |
input_prompt = input_prompt + interaction[0] + " [/INST] " + interaction[1] + " </s><s> [INST] "
|
25 |
|
26 |
input_prompt = input_prompt + message + " [/INST] "
|
27 |
|
28 |
-
print(f"Logging: input_prompt is - {input_prompt}")
|
29 |
data = {
|
30 |
"inputs": input_prompt,
|
31 |
"parameters": {"max_new_tokens":256}
|
32 |
}
|
33 |
|
34 |
-
#response = requests.post(api_url, headers=headers, data=json.dumps(data), auth=('hf', hf_token))
|
35 |
-
|
36 |
-
#print(f'Logging: API response is - {response.text}')
|
37 |
-
#response_json_object = json.loads(response.text)
|
38 |
-
#return response_json_object[0]['generated_text']
|
39 |
-
|
40 |
response = requests.post(api_url, headers=headers, data=json.dumps(data), auth=('hf', hf_token), stream=True)
|
41 |
|
42 |
partial_message = ""
|
@@ -49,12 +39,11 @@ def predict(message, chatbot):
|
|
49 |
if decoded_line.startswith('data:'):
|
50 |
json_line = decoded_line[5:] # Exclude the first 5 characters ('data:')
|
51 |
else:
|
52 |
-
|
53 |
continue
|
54 |
|
55 |
# Load as JSON
|
56 |
try:
|
57 |
-
#print(json.loads(json_line)['token']['text'])
|
58 |
partial_message = partial_message + json.loads(json_line)['token']['text']
|
59 |
yield partial_message
|
60 |
except json.JSONDecodeError:
|
|
|
16 |
|
17 |
def predict(message, chatbot):
|
18 |
|
|
|
|
|
|
|
19 |
input_prompt = f"[INST]<<SYS>>\n{system_message}\n<</SYS>>\n\n "
|
20 |
for interaction in chatbot:
|
21 |
input_prompt = input_prompt + interaction[0] + " [/INST] " + interaction[1] + " </s><s> [INST] "
|
22 |
|
23 |
input_prompt = input_prompt + message + " [/INST] "
|
24 |
|
|
|
25 |
data = {
|
26 |
"inputs": input_prompt,
|
27 |
"parameters": {"max_new_tokens":256}
|
28 |
}
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
response = requests.post(api_url, headers=headers, data=json.dumps(data), auth=('hf', hf_token), stream=True)
|
31 |
|
32 |
partial_message = ""
|
|
|
39 |
if decoded_line.startswith('data:'):
|
40 |
json_line = decoded_line[5:] # Exclude the first 5 characters ('data:')
|
41 |
else:
|
42 |
+
gr.Warning("This line does not start with 'data:':", decoded_line)
|
43 |
continue
|
44 |
|
45 |
# Load as JSON
|
46 |
try:
|
|
|
47 |
partial_message = partial_message + json.loads(json_line)['token']['text']
|
48 |
yield partial_message
|
49 |
except json.JSONDecodeError:
|