dlflannery commited on
Commit
8f70b7b
·
verified ·
1 Parent(s): 3570412

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -52,6 +52,11 @@ GOOGLE_KEY=os.getenv('GOOGLE_KEY')
52
  # mimes = {'pdf': 'application/pdf', 'txt': 'text/plain',
53
  # 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'}
54
 
 
 
 
 
 
55
  @function_tool
56
  async def google_route(loc1: str, loc2: str, prefer_public: bool, scenic_route: bool):
57
  '''Uses Google Maps API to obtain a route plan overview, and distance in miles and duration
@@ -169,6 +174,8 @@ async def make_pdf(text: str, title: str)->str:
169
  pdf.add_section(Section(text))
170
  outpath = os.path.join('./','document.pdf')
171
  pdf.save(outpath)
 
 
172
  return title
173
 
174
  @function_tool
@@ -248,6 +255,7 @@ def updatePassword(pwd, user):
248
  password = 'none'
249
  if user in unames:
250
  pwd = pwd.lower().strip()
 
251
  if pwd == pwd_list[unames.index(user)]:
252
  password = pwd
253
  return [password, "*********",
@@ -483,8 +491,9 @@ async def chat(prompt_window, user_window, password, history, output_window,
483
  # bin_out = base64.b64decode(raw_data)
484
  # with open('./document.pdf', 'w', encoding='utf-8') as fp:
485
  # fp.write(raw_data)
486
- file_download = gr.DownloadButton(label=f'Download PDF Doc',
487
- visible=True, value='./document.pdf')
 
488
 
489
 
490
  if item.type == "reasoning_item":
@@ -602,6 +611,7 @@ with gr.Blocks() as demo:
602
  uploaded_file_paths = gr.State([])
603
  history = gr.State([])
604
  inputs = gr.State([])
 
605
 
606
  gr.Markdown('# GPT Agent')
607
  gr.Markdown('Enter user name & password. Tap "Help & Hints" button for more instructions.')
@@ -620,7 +630,10 @@ with gr.Blocks() as demo:
620
  gr.Markdown('### **Dialog:**')
621
  #output_window = gr.Text(container=True, label='Dialog')
622
  output_window = gr.Markdown(container=True)
623
- file_download = gr.DownloadButton(label='Download File', visible=False, value=None)
 
 
 
624
  with gr.Row():
625
  with gr.Column():
626
  image_window2 = gr.Image(visible=False, interactive=True, label='Image to Analyze',
@@ -645,13 +658,14 @@ with gr.Blocks() as demo:
645
  inputs=[image_window2, user, output_window, uploaded_image_files],
646
  outputs=[uploaded_image_files, output_window])
647
  pwd_window.blur(updatePassword,
648
- inputs = [pwd_window, user],
649
- outputs = [password, pwd_window, button_upload_file, button_get_image])
650
  button_upload_file.click(fn=upload_file, inputs=[user, password, output_window],
651
  outputs=[file_uploader, output_window])
652
  file_uploader.upload(fn=load_file, inputs=[file_uploader, output_window, uploaded_file_paths],
653
  outputs=[uploaded_file_paths, output_window, file_uploader])
654
  # demo.launch(share=True, allowed_paths=[dataDir], ssr_mode=False)
655
- # demo.load(delete_db_files)
656
  demo.unload(clean_up_files)
 
657
  demo.launch(share=True, ssr_mode=False, theme=gr.themes.Soft())
 
52
  # mimes = {'pdf': 'application/pdf', 'txt': 'text/plain',
53
  # 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'}
54
 
55
+ # def reset_download():
56
+ # clean_up_files()
57
+ # return [gr.Timer(active=False),
58
+ # gr.DownloadButton(label='Download the File', visible=False, value=None)]
59
+
60
  @function_tool
61
  async def google_route(loc1: str, loc2: str, prefer_public: bool, scenic_route: bool):
62
  '''Uses Google Maps API to obtain a route plan overview, and distance in miles and duration
 
174
  pdf.add_section(Section(text))
175
  outpath = os.path.join('./','document.pdf')
176
  pdf.save(outpath)
177
+ # os.chmod(outpath,
178
+ # stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH | stat.S_IXGRP | stat.S_IXOTH | stat.S_IXUSR)
179
  return title
180
 
181
  @function_tool
 
255
  password = 'none'
256
  if user in unames:
257
  pwd = pwd.lower().strip()
258
+ # dl_button = gr.DownloadButton(value=None, visible=False)
259
  if pwd == pwd_list[unames.index(user)]:
260
  password = pwd
261
  return [password, "*********",
 
491
  # bin_out = base64.b64decode(raw_data)
492
  # with open('./document.pdf', 'w', encoding='utf-8') as fp:
493
  # fp.write(raw_data)
494
+ file_download = gr.DownloadButton( #label=f'Download PDF Doc',
495
+ visible=True, value=Path('./document.pdf'))
496
+ # interactive=True)
497
 
498
 
499
  if item.type == "reasoning_item":
 
611
  uploaded_file_paths = gr.State([])
612
  history = gr.State([])
613
  inputs = gr.State([])
614
+ # timer = gr.Timer(value=2.0, active=True)
615
 
616
  gr.Markdown('# GPT Agent')
617
  gr.Markdown('Enter user name & password. Tap "Help & Hints" button for more instructions.')
 
630
  gr.Markdown('### **Dialog:**')
631
  #output_window = gr.Text(container=True, label='Dialog')
632
  output_window = gr.Markdown(container=True)
633
+ # file_download = gr.DownloadButton(label='Download File', visible=False, value=None)
634
+ file_download = gr.DownloadButton("Click to download file", visible=False,
635
+ value=None)
636
+ # value="http://www.marketingtool.online/en/face-generator/img/faces/avatar-1151ce9f4b2043de0d2e3b7826127998.jpg")
637
  with gr.Row():
638
  with gr.Column():
639
  image_window2 = gr.Image(visible=False, interactive=True, label='Image to Analyze',
 
658
  inputs=[image_window2, user, output_window, uploaded_image_files],
659
  outputs=[uploaded_image_files, output_window])
660
  pwd_window.blur(updatePassword,
661
+ inputs = [pwd_window, user],
662
+ outputs = [password, pwd_window, button_upload_file, button_get_image])
663
  button_upload_file.click(fn=upload_file, inputs=[user, password, output_window],
664
  outputs=[file_uploader, output_window])
665
  file_uploader.upload(fn=load_file, inputs=[file_uploader, output_window, uploaded_file_paths],
666
  outputs=[uploaded_file_paths, output_window, file_uploader])
667
  # demo.launch(share=True, allowed_paths=[dataDir], ssr_mode=False)
668
+ # demo.load(fn=clean_up_files, inputs=[], outputs=[])
669
  demo.unload(clean_up_files)
670
+ # timer.tick(fn=reset_download, inputs=[], outputs=[timer,file_download])
671
  demo.launch(share=True, ssr_mode=False, theme=gr.themes.Soft())