theguywhosucks commited on
Commit
9975a15
·
verified ·
1 Parent(s): 906b26c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -25
app.py CHANGED
@@ -8,8 +8,8 @@ from gradio_client import Client, handle_file
8
  SPACE = "pockit-cloud/main"
9
  client = Client(SPACE)
10
 
11
- # Set your Space URL
12
  SPACE_URL = os.getenv("SPACE_URL", "https://pockit-cloud-main.hf.space")
 
13
 
14
  TMP_DIR = "tmp"
15
  os.makedirs(TMP_DIR, exist_ok=True)
@@ -21,9 +21,8 @@ def cleanup_tmp():
21
  now = time.time()
22
  for f in os.listdir(TMP_DIR):
23
  path = os.path.join(TMP_DIR, f)
24
- if os.path.isfile(path):
25
- if now - os.path.getmtime(path) > 3600:
26
- os.remove(path)
27
 
28
  # -------------------------
29
  # LOGIN
@@ -106,17 +105,19 @@ def download_file(user_id, password, filename):
106
  temp_name = f"{uuid.uuid4()}_{filename}"
107
  temp_path = os.path.join(TMP_DIR, temp_name)
108
 
109
- subprocess.run(
110
- [
111
- "wget",
112
- "--tries=3",
113
- "--no-check-certificate",
114
- "-O",
115
- temp_path,
116
- link
117
- ],
118
- check=True
119
- )
 
 
120
 
121
  return f"{SPACE_URL}/file={temp_path}"
122
 
@@ -173,9 +174,6 @@ with gr.Blocks(title="Pockit Cloud Client") as app:
173
  user = gr.Textbox(label="User ID")
174
  pw = gr.Textbox(label="Password", type="password")
175
 
176
- # -------------------------
177
- # LOGIN TAB
178
- # -------------------------
179
  with gr.Tab("Login"):
180
  login_btn = gr.Button("Login")
181
  login_status = gr.Textbox(label="Status")
@@ -187,9 +185,6 @@ with gr.Blocks(title="Pockit Cloud Client") as app:
187
  outputs=[login_status, login_files]
188
  )
189
 
190
- # -------------------------
191
- # FILES TAB
192
- # -------------------------
193
  with gr.Tab("Files"):
194
 
195
  refresh_btn = gr.Button("Refresh File List")
@@ -202,7 +197,7 @@ with gr.Blocks(title="Pockit Cloud Client") as app:
202
  outputs=[status_box, file_list]
203
  )
204
 
205
- gr.Markdown("### Download File (Temporary Mirror)")
206
 
207
  download_btn = gr.Button("Download")
208
  download_output = gr.Textbox(label="Download Link")
@@ -237,9 +232,6 @@ with gr.Blocks(title="Pockit Cloud Client") as app:
237
  outputs=delete_status
238
  )
239
 
240
- # -------------------------
241
- # PASSWORD TAB
242
- # -------------------------
243
  with gr.Tab("Password"):
244
  new_pw = gr.Textbox(label="New Password", type="password")
245
  change_btn = gr.Button("Change Password")
 
8
  SPACE = "pockit-cloud/main"
9
  client = Client(SPACE)
10
 
 
11
  SPACE_URL = os.getenv("SPACE_URL", "https://pockit-cloud-main.hf.space")
12
+ HF_TOKEN = os.getenv("HF_TOKEN")
13
 
14
  TMP_DIR = "tmp"
15
  os.makedirs(TMP_DIR, exist_ok=True)
 
21
  now = time.time()
22
  for f in os.listdir(TMP_DIR):
23
  path = os.path.join(TMP_DIR, f)
24
+ if os.path.isfile(path) and now - os.path.getmtime(path) > 3600:
25
+ os.remove(path)
 
26
 
27
  # -------------------------
28
  # LOGIN
 
105
  temp_name = f"{uuid.uuid4()}_{filename}"
106
  temp_path = os.path.join(TMP_DIR, temp_name)
107
 
108
+ wget_cmd = [
109
+ "wget",
110
+ "--tries=3",
111
+ "--no-check-certificate",
112
+ "-O",
113
+ temp_path,
114
+ link
115
+ ]
116
+
117
+ if HF_TOKEN:
118
+ wget_cmd.insert(1, f"--header=Authorization: Bearer {HF_TOKEN}")
119
+
120
+ subprocess.run(wget_cmd, check=True)
121
 
122
  return f"{SPACE_URL}/file={temp_path}"
123
 
 
174
  user = gr.Textbox(label="User ID")
175
  pw = gr.Textbox(label="Password", type="password")
176
 
 
 
 
177
  with gr.Tab("Login"):
178
  login_btn = gr.Button("Login")
179
  login_status = gr.Textbox(label="Status")
 
185
  outputs=[login_status, login_files]
186
  )
187
 
 
 
 
188
  with gr.Tab("Files"):
189
 
190
  refresh_btn = gr.Button("Refresh File List")
 
197
  outputs=[status_box, file_list]
198
  )
199
 
200
+ gr.Markdown("### Download File")
201
 
202
  download_btn = gr.Button("Download")
203
  download_output = gr.Textbox(label="Download Link")
 
232
  outputs=delete_status
233
  )
234
 
 
 
 
235
  with gr.Tab("Password"):
236
  new_pw = gr.Textbox(label="New Password", type="password")
237
  change_btn = gr.Button("Change Password")