Update app.py
Browse files
app.py
CHANGED
@@ -65,12 +65,14 @@ repo = Repository(
|
|
65 |
local_dir="dataset", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
66 |
)
|
67 |
|
68 |
-
|
69 |
-
|
|
|
|
|
70 |
with open(DATA_FILE, "a") as csvfile:
|
71 |
writer = csv.DictWriter(csvfile, fieldnames=["request", "response", "time"])
|
72 |
writer.writerow(
|
73 |
-
{"request":
|
74 |
)
|
75 |
commit_url = repo.push_to_hub()
|
76 |
app.logger.info(commit_url)
|
@@ -224,7 +226,18 @@ def generate_search_request():
|
|
224 |
|
225 |
# Use Response to stream tokens
|
226 |
return Response(generate_tokens(model, generator), content_type='text/plain', status=200, direct_passthrough=True)
|
227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
@app.route('/', methods=['POST'])
|
229 |
def generate_response():
|
230 |
global stop_generation
|
@@ -278,18 +291,10 @@ def generate_response():
|
|
278 |
app.logger.info('Generator created')
|
279 |
|
280 |
|
281 |
-
|
282 |
-
def generate_and_log_tokens(model, generator):
|
283 |
-
global response_tokens
|
284 |
-
for token in generate_tokens(model, generator):
|
285 |
-
if token == b'': # or (max_new_tokens is not None and i >= max_new_tokens):
|
286 |
-
log(user_request, response_tokens.decode("utf-8", errors="ignore"))
|
287 |
-
break
|
288 |
-
response_tokens += token
|
289 |
-
yield token
|
290 |
|
291 |
# Use Response to stream tokens
|
292 |
-
return Response(generate_and_log_tokens(model, generator), content_type='text/plain', status=200, direct_passthrough=True)
|
293 |
|
294 |
|
295 |
|
|
|
65 |
local_dir="dataset", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN
|
66 |
)
|
67 |
|
68 |
+
|
69 |
+
|
70 |
+
def log(req: str = '', resp: str = ''):
|
71 |
+
if req or resp:
|
72 |
with open(DATA_FILE, "a") as csvfile:
|
73 |
writer = csv.DictWriter(csvfile, fieldnames=["request", "response", "time"])
|
74 |
writer.writerow(
|
75 |
+
{"request": req, "response": resp, "time": str(datetime.now())}
|
76 |
)
|
77 |
commit_url = repo.push_to_hub()
|
78 |
app.logger.info(commit_url)
|
|
|
226 |
|
227 |
# Use Response to stream tokens
|
228 |
return Response(generate_tokens(model, generator), content_type='text/plain', status=200, direct_passthrough=True)
|
229 |
+
|
230 |
+
response_tokens = ''
|
231 |
+
def generate_and_log_tokens(user_request, model, generator):
|
232 |
+
global response_tokens
|
233 |
+
for token in generate_tokens(model, generator):
|
234 |
+
if token == b'': # or (max_new_tokens is not None and i >= max_new_tokens):
|
235 |
+
log(user_request, response_tokens.decode("utf-8", errors="ignore"))
|
236 |
+
response_tokens = ''
|
237 |
+
break
|
238 |
+
response_tokens += token
|
239 |
+
yield token
|
240 |
+
|
241 |
@app.route('/', methods=['POST'])
|
242 |
def generate_response():
|
243 |
global stop_generation
|
|
|
291 |
app.logger.info('Generator created')
|
292 |
|
293 |
|
294 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
# Use Response to stream tokens
|
297 |
+
return Response(generate_and_log_tokens(user_request, model, generator), content_type='text/plain', status=200, direct_passthrough=True)
|
298 |
|
299 |
|
300 |
|