tecuts commited on
Commit
2e5512b
·
verified ·
1 Parent(s): fba3703

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -102,18 +102,19 @@ class DownloadResponse(BaseModel):
102
 
103
 
104
  # Function to wait until the file is fully downloaded
105
- def wait_for_file_to_complete(file_path, initial_size, max_wait_time=30):
106
  wait_time = 0
107
  while True:
108
  current_size = os.path.getsize(file_path)
109
  if current_size == initial_size:
110
  wait_time += 1
111
  if wait_time >= max_wait_time:
 
112
  break
113
  else:
114
  wait_time = 0
115
  initial_size = current_size
116
- time.sleep(1)
117
 
118
  @app.post("/download", response_model=DownloadResponse)
119
  async def download_file(request: DownloadRequest):
@@ -159,6 +160,10 @@ async def download_file(request: DownloadRequest):
159
  file_size = os.path.getsize(os.path.join(download_subdir, downloaded_file))
160
  logger.info(f"Final file size: {file_size} bytes")
161
 
 
 
 
 
162
  # Generate the download URL and URL encode the filename
163
  space_url = os.getenv("SPACE_URL", "https://tecuts-vob.hf.space")
164
  encoded_filename = quote(downloaded_file)
@@ -187,8 +192,6 @@ async def download_file(request: DownloadRequest):
187
  )
188
 
189
 
190
-
191
-
192
  @app.get("/test")
193
  async def test():
194
  """Test endpoint to verify setup"""
 
102
 
103
 
104
  # Function to wait until the file is fully downloaded
105
+ def wait_for_file_to_complete(file_path, initial_size, max_wait_time=60):
106
  wait_time = 0
107
  while True:
108
  current_size = os.path.getsize(file_path)
109
  if current_size == initial_size:
110
  wait_time += 1
111
  if wait_time >= max_wait_time:
112
+ logger.info(f"Timeout reached waiting for file to complete: {file_path}")
113
  break
114
  else:
115
  wait_time = 0
116
  initial_size = current_size
117
+ time.sleep(2) # Wait 2 seconds before checking again
118
 
119
  @app.post("/download", response_model=DownloadResponse)
120
  async def download_file(request: DownloadRequest):
 
160
  file_size = os.path.getsize(os.path.join(download_subdir, downloaded_file))
161
  logger.info(f"Final file size: {file_size} bytes")
162
 
163
+ # If the size is still incorrect, raise an error
164
+ if file_size < 7_000_000: # Assuming 7 MB is the minimum expected file size
165
+ raise Exception(f"File seems incomplete. Final size: {file_size} bytes.")
166
+
167
  # Generate the download URL and URL encode the filename
168
  space_url = os.getenv("SPACE_URL", "https://tecuts-vob.hf.space")
169
  encoded_filename = quote(downloaded_file)
 
192
  )
193
 
194
 
 
 
195
  @app.get("/test")
196
  async def test():
197
  """Test endpoint to verify setup"""