Update app.py
Browse files
app.py
CHANGED
@@ -292,61 +292,7 @@ def reply_generate(prompt, history,post_check,full_conv,persona1, agent_name=age
|
|
292 |
#except Exception as e:
|
293 |
# print(e)
|
294 |
return "",history,out_json,out_json,out_json,html_out
|
295 |
-
|
296 |
-
'''
|
297 |
-
hist_out.append(out_json)
|
298 |
-
#try:
|
299 |
-
# for ea in
|
300 |
-
with open(f'{uid}.json', 'w') as f:
|
301 |
-
json_hist=json.dumps(hist_out, indent=4)
|
302 |
-
f.write(json_hist)
|
303 |
-
f.close()
|
304 |
-
|
305 |
-
upload_file(
|
306 |
-
path_or_fileobj =f"{uid}.json",
|
307 |
-
path_in_repo = f"book1/{filename}.json",
|
308 |
-
repo_id =f"{username}/{dataset_name}",
|
309 |
-
repo_type = "dataset",
|
310 |
-
token=token,
|
311 |
-
)
|
312 |
-
|
313 |
-
|
314 |
-
#out_json = {'user':"",'datetime':current_time,'title':title,'blog':1,'comment':0,'reply':0,"prompt":prompt,"output":output}
|
315 |
-
#full_conv[-1]+=(output,)
|
316 |
-
#full_conv.append((None,None,output))
|
317 |
-
html_out=load_html(post_check)
|
318 |
-
|
319 |
-
file_n = f'{post_check["filename"]}.json'
|
320 |
-
print(file_n)
|
321 |
-
r = requests.get(f'{save_data}book1/{file_n}')
|
322 |
-
print(f'status code main:: {r.status_code}')
|
323 |
-
if r.status_code==200:
|
324 |
-
try:
|
325 |
-
lod = json.loads(r.text)
|
326 |
-
print(f'lod:: {lod}')
|
327 |
-
lod[0]['reply']=lod[0]['reply']+1
|
328 |
-
lod[0]['comment_list'][0]['reply_list'].append({'user':persona[persona1]['name'],'datetime':'','reply':output})
|
329 |
-
#hist_out.append(out_json)
|
330 |
-
#try:
|
331 |
-
# for ea in
|
332 |
-
with open(f'{uid}.json', 'w') as f:
|
333 |
-
json_hist=json.dumps(lod, indent=4)
|
334 |
-
f.write(json_hist)
|
335 |
-
f.close()
|
336 |
-
|
337 |
-
upload_file(
|
338 |
-
path_or_fileobj =f"{uid}.json",
|
339 |
-
path_in_repo = f"book1/{file_n}",
|
340 |
-
repo_id =f"{username}/{dataset_name}",
|
341 |
-
repo_type = "dataset",
|
342 |
-
token=token,
|
343 |
-
)
|
344 |
-
except Exception as e:
|
345 |
-
print(e)
|
346 |
-
return "",history,lod[0],lod[0],lod[0],html_out
|
347 |
-
'''
|
348 |
-
|
349 |
-
|
350 |
|
351 |
|
352 |
def create_valid_filename(invalid_filename: str) -> str:
|
@@ -361,10 +307,6 @@ def create_valid_filename(invalid_filename: str) -> str:
|
|
361 |
return ''.join(char for char in valid_chars if char in allowed_chars)
|
362 |
|
363 |
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
def load_html(conv):
|
369 |
ht=""
|
370 |
comm=0
|
@@ -378,9 +320,9 @@ def load_html(conv):
|
|
378 |
if conv['comment_list']:
|
379 |
for com in conv['comment_list']:
|
380 |
ht+=f"""<pre class="resp1"><div class="bhead"></div>{com}</pre>"""
|
381 |
-
for ea in conv['comment_list']:
|
382 |
-
if conv['comment_list'][
|
383 |
-
for repl in conv['comment_list'][
|
384 |
ht+=f"""<pre class="resp2"><div class="bhead"></div>{repl}</pre>"""
|
385 |
ht+=f"""</div>"""
|
386 |
'''
|
|
|
292 |
#except Exception as e:
|
293 |
# print(e)
|
294 |
return "",history,out_json,out_json,out_json,html_out
|
295 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
|
297 |
|
298 |
def create_valid_filename(invalid_filename: str) -> str:
|
|
|
307 |
return ''.join(char for char in valid_chars if char in allowed_chars)
|
308 |
|
309 |
|
|
|
|
|
|
|
|
|
310 |
def load_html(conv):
|
311 |
ht=""
|
312 |
comm=0
|
|
|
320 |
if conv['comment_list']:
|
321 |
for com in conv['comment_list']:
|
322 |
ht+=f"""<pre class="resp1"><div class="bhead"></div>{com}</pre>"""
|
323 |
+
for i,ea in enumerate(conv['comment_list']):
|
324 |
+
if conv['comment_list'][i]['reply_list']:
|
325 |
+
for repl in conv['comment_list'][i]['reply_list']:
|
326 |
ht+=f"""<pre class="resp2"><div class="bhead"></div>{repl}</pre>"""
|
327 |
ht+=f"""</div>"""
|
328 |
'''
|