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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -8,6 +8,9 @@ from gradio_client import Client, handle_file
8
  SPACE = "pockit-cloud/main"
9
  client = Client(SPACE)
10
 
 
 
 
11
  TMP_DIR = "tmp"
12
  os.makedirs(TMP_DIR, exist_ok=True)
13
 
@@ -19,7 +22,7 @@ def cleanup_tmp():
19
  for f in os.listdir(TMP_DIR):
20
  path = os.path.join(TMP_DIR, f)
21
  if os.path.isfile(path):
22
- if now - os.path.getmtime(path) > 3600: # 1 hour
23
  os.remove(path)
24
 
25
  # -------------------------
@@ -80,7 +83,7 @@ def upload_file(user_id, password, file, custom_name):
80
  return str(e)
81
 
82
  # -------------------------
83
- # DOWNLOAD USING WGET TEMP
84
  # -------------------------
85
  def download_file(user_id, password, filename):
86
 
@@ -104,11 +107,18 @@ def download_file(user_id, password, filename):
104
  temp_path = os.path.join(TMP_DIR, temp_name)
105
 
106
  subprocess.run(
107
- ["wget", "-q", "-O", temp_path, link],
 
 
 
 
 
 
 
108
  check=True
109
  )
110
 
111
- return f"/file={temp_path}"
112
 
113
  except Exception as e:
114
  return str(e)
@@ -192,9 +202,9 @@ with gr.Blocks(title="Pockit Cloud Client") as app:
192
  outputs=[status_box, file_list]
193
  )
194
 
195
- gr.Markdown("### Download File")
196
 
197
- download_btn = gr.Button("Download (Temporary Mirror)")
198
  download_output = gr.Textbox(label="Download Link")
199
 
200
  download_btn.click(
 
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)
16
 
 
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
  # -------------------------
 
83
  return str(e)
84
 
85
  # -------------------------
86
+ # DOWNLOAD USING WGET MIRROR
87
  # -------------------------
88
  def download_file(user_id, password, filename):
89
 
 
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
 
123
  except Exception as e:
124
  return str(e)
 
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")
209
 
210
  download_btn.click(