theguywhosucks commited on
Commit
753aca2
·
verified ·
1 Parent(s): 5b0ba07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -16
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import os
2
- import requests
3
  import gradio as gr
4
  from gradio_client import Client, handle_file
5
 
@@ -64,15 +63,15 @@ def upload_file(user_id, password, file, custom_name):
64
  return str(e)
65
 
66
  # -------------------------
67
- # DOWNLOAD FILE
68
  # -------------------------
69
  def download_file(user_id, password, filename):
70
 
71
  if not user_id or not password:
72
- return None
73
 
74
  if not filename:
75
- return None
76
 
77
  try:
78
  link = client.predict(
@@ -82,18 +81,10 @@ def download_file(user_id, password, filename):
82
  api_name="/get_download_link_action"
83
  )
84
 
85
- r = requests.get(link)
86
-
87
- os.makedirs("downloads", exist_ok=True)
88
- path = f"downloads/{filename}"
89
 
90
- with open(path, "wb") as f:
91
- f.write(r.content)
92
-
93
- return path
94
  except Exception as e:
95
- print(e)
96
- return None
97
 
98
  # -------------------------
99
  # PASSWORD CHANGE
@@ -146,8 +137,8 @@ with gr.Blocks(title="Pockit Cloud Client") as app:
146
  outputs=[status_box, file_list]
147
  )
148
 
149
- download_btn = gr.Button("Download Selected File")
150
- download_output = gr.File(label="Downloaded File")
151
 
152
  download_btn.click(
153
  download_file,
 
1
  import os
 
2
  import gradio as gr
3
  from gradio_client import Client, handle_file
4
 
 
63
  return str(e)
64
 
65
  # -------------------------
66
+ # GET DOWNLOAD LINK ONLY
67
  # -------------------------
68
  def download_file(user_id, password, filename):
69
 
70
  if not user_id or not password:
71
+ return "Username and password required"
72
 
73
  if not filename:
74
+ return "No file selected"
75
 
76
  try:
77
  link = client.predict(
 
81
  api_name="/get_download_link_action"
82
  )
83
 
84
+ return link # just display the link
 
 
 
85
 
 
 
 
 
86
  except Exception as e:
87
+ return str(e)
 
88
 
89
  # -------------------------
90
  # PASSWORD CHANGE
 
137
  outputs=[status_box, file_list]
138
  )
139
 
140
+ download_btn = gr.Button("Get Download Link")
141
+ download_output = gr.Textbox(label="Download Link")
142
 
143
  download_btn.click(
144
  download_file,