Omnibus commited on
Commit
19bd445
·
verified ·
1 Parent(s): a312e0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -17
app.py CHANGED
@@ -393,23 +393,49 @@ def find_rss():
393
  yield out_box,[(None,f'Source is current as of:\n{timestamp} UTC\n\nThe current Date and Time is:\n{timestamp} UTC')]
394
 
395
 
396
- def load_data():
397
- yield None,[(None,f'Loading data source, please wait')]
398
-
399
- f_ist = (api.list_repo_files(repo_id=reponame, repo_type="dataset"))
400
- f_ist.sort(reverse=True)
401
- print(f_ist)
402
- r = requests.get(f'{save_data}{f_ist[0]}')
403
- lod = json.loads(r.text)
404
  timestamp=str(datetime.datetime.now())
405
- filename=f_ist[0].split("/")[1].split(".json")[0].replace("--"," ")
406
- print (filename)
407
- filename_start = filename.split(" ")[0]
408
- filename_end = filename.split(" ")[1]
409
- filename_end = filename_end.replace("-"[0],":").replace("-"[0],":").replace("-"[0],".")
410
- #filename_end_far=filename_end.split(":")[2]
411
- print (filename)
412
- yield lod,[(None,f'Source is current as of:\n{filename_start} {filename_end} UTC\n\nThe current Date and Time is:\n{timestamp} UTC')]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
 
414
  with gr.Blocks() as app:
415
  cb = gr.Chatbot(height=600, show_share_button=True, show_copy_button=True)
@@ -417,14 +443,16 @@ with gr.Blocks() as app:
417
  inst = gr.Textbox(label="Instructions")
418
  sub_btn=gr.Button("Submit")
419
  with gr.Row():
 
420
  load_btn = gr.Button("Load RSS")
 
421
  u_btn=gr.Button("Update [RSS Data]")
422
  keyw = gr.Button("Use Keyword [Experimental]")
423
  with gr.Row():
424
  out_json = gr.JSON()
425
  fil = gr.Textbox()
426
  keyw.click(get_records,[inst,out_json],[inst,cb])
427
- load_btn.click(load_data,None,[out_json,cb])
428
  u_btn.click(find_rss,None,[out_json,cb])
429
  sub_btn.click(summarize,[inst,cb,out_json],[inst,cb])
430
  app.queue(default_concurrency_limit=20).launch()
 
393
  yield out_box,[(None,f'Source is current as of:\n{timestamp} UTC\n\nThe current Date and Time is:\n{timestamp} UTC')]
394
 
395
 
396
+ def load_data(inp=None):
 
 
 
 
 
 
 
397
  timestamp=str(datetime.datetime.now())
398
+ yield None,[(None,f'Loading data source, please wait')]
399
+ if inp:
400
+ yield None,[(None,f'Loading data from {inp}, please wait')]
401
+
402
+ r = requests.get(f'{inp}')
403
+ if r.status_code == 200:
404
+ lod={}
405
+ try:
406
+ if ".json" in rss_url:
407
+ lod = json.loads(r.text)
408
+ if ".xml" in rss_url:
409
+ lod = xmltodict.parse(r.content)
410
+ if ".rss" in rss_url:
411
+ lod = xmltodict.parse(r.content)
412
+ else:
413
+ try:
414
+ lod = xmltodict.parse(r.content)
415
+ except Exception as e:
416
+ yield None, [(None, f'{rss_url} ::ERROR:: {e}')]
417
+ except Exception as e:
418
+ yield None, [(None, f'{rss_url} ::ERROR:: {e}')]
419
+ yield lod,[(None,f'Source is current as of:\n{timestamp} UTC')]
420
+ else:
421
+ lod =
422
+ yield None, [(None, f'{rss_url} ::ERROR::COULD NOT CONNECT:: {r.status_code}')]
423
+ if not inp:
424
+ yield None,[(None,f'Loading data from database, please wait')]
425
+
426
+ f_ist = (api.list_repo_files(repo_id=reponame, repo_type="dataset"))
427
+ f_ist.sort(reverse=True)
428
+ print(f_ist)
429
+ r = requests.get(f'{save_data}{f_ist[0]}')
430
+ lod = json.loads(r.text)
431
+ filename=f_ist[0].split("/")[1].split(".json")[0].replace("--"," ")
432
+ print (filename)
433
+ filename_start = filename.split(" ")[0]
434
+ filename_end = filename.split(" ")[1]
435
+ filename_end = filename_end.replace("-"[0],":").replace("-"[0],":").replace("-"[0],".")
436
+ #filename_end_far=filename_end.split(":")[2]
437
+ print (filename)
438
+ yield lod,[(None,f'Source is current as of:\n{filename_start} {filename_end} UTC\n\nThe current Date and Time is:\n{timestamp} UTC')]
439
 
440
  with gr.Blocks() as app:
441
  cb = gr.Chatbot(height=600, show_share_button=True, show_copy_button=True)
 
443
  inst = gr.Textbox(label="Instructions")
444
  sub_btn=gr.Button("Submit")
445
  with gr.Row():
446
+ rss_custom=gr.Textbox("URL for RSS feed (.rss,.xml)")
447
  load_btn = gr.Button("Load RSS")
448
+ with gr.Accordion():
449
  u_btn=gr.Button("Update [RSS Data]")
450
  keyw = gr.Button("Use Keyword [Experimental]")
451
  with gr.Row():
452
  out_json = gr.JSON()
453
  fil = gr.Textbox()
454
  keyw.click(get_records,[inst,out_json],[inst,cb])
455
+ load_btn.click(load_data,rss_custom,[out_json,cb])
456
  u_btn.click(find_rss,None,[out_json,cb])
457
  sub_btn.click(summarize,[inst,cb,out_json],[inst,cb])
458
  app.queue(default_concurrency_limit=20).launch()