Spaces:
Build error
Build error
Commit
·
6be365f
1
Parent(s):
c603936
fix
Browse files- app.py +6 -0
- hf_scrapper.py +12 -8
app.py
CHANGED
|
@@ -154,6 +154,12 @@ def get_film_store():
|
|
| 154 |
return jsonify({}), 404
|
| 155 |
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
# Main entry point
|
| 158 |
if __name__ == "__main__":
|
| 159 |
app.run(debug=True, host="0.0.0.0", port=7860)
|
|
|
|
| 154 |
return jsonify({}), 404
|
| 155 |
|
| 156 |
|
| 157 |
+
|
| 158 |
+
# Routes
|
| 159 |
+
@app.route('/')
|
| 160 |
+
def index():
|
| 161 |
+
return "Server Runing"
|
| 162 |
+
|
| 163 |
# Main entry point
|
| 164 |
if __name__ == "__main__":
|
| 165 |
app.run(debug=True, host="0.0.0.0", port=7860)
|
hf_scrapper.py
CHANGED
|
@@ -49,7 +49,7 @@ def download_file(file_url, token, cache_path, proxies, film_id, title, chunk_si
|
|
| 49 |
response.raise_for_status()
|
| 50 |
|
| 51 |
total_size = int(response.headers.get('content-length', 0))
|
| 52 |
-
download_progress[film_id] = {"total": total_size, "downloaded": 0}
|
| 53 |
|
| 54 |
os.makedirs(os.path.dirname(cache_path), exist_ok=True)
|
| 55 |
with open(cache_path, 'wb') as file, tqdm(total=total_size, unit='B', unit_scale=True, desc=cache_path) as pbar:
|
|
@@ -60,13 +60,17 @@ def download_file(file_url, token, cache_path, proxies, film_id, title, chunk_si
|
|
| 60 |
|
| 61 |
print(f'File cached to {cache_path} successfully.')
|
| 62 |
update_film_store_json(title, cache_path)
|
|
|
|
| 63 |
except RequestException as e:
|
| 64 |
print(f"Error downloading file: {e}")
|
|
|
|
| 65 |
except IOError as e:
|
| 66 |
print(f"Error writing file {cache_path}: {e}")
|
|
|
|
| 67 |
finally:
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
def get_download_progress(film_id):
|
| 72 |
"""
|
|
@@ -76,14 +80,15 @@ def get_download_progress(film_id):
|
|
| 76 |
film_id (str): The unique identifier for the film download.
|
| 77 |
|
| 78 |
Returns:
|
| 79 |
-
dict: A dictionary containing the total size, downloaded size,
|
| 80 |
"""
|
| 81 |
if film_id in download_progress:
|
| 82 |
total = download_progress[film_id]["total"]
|
| 83 |
downloaded = download_progress[film_id]["downloaded"]
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
| 87 |
|
| 88 |
def update_film_store_json(title, cache_path):
|
| 89 |
"""
|
|
@@ -106,7 +111,6 @@ def update_film_store_json(title, cache_path):
|
|
| 106 |
json.dump(film_store_data, json_file, indent=2)
|
| 107 |
print(f'Film store updated with {title}.')
|
| 108 |
|
| 109 |
-
|
| 110 |
def get_file_structure(repo, token, path="", proxies=None):
|
| 111 |
"""
|
| 112 |
Fetches the file structure of a specified Hugging Face repository.
|
|
|
|
| 49 |
response.raise_for_status()
|
| 50 |
|
| 51 |
total_size = int(response.headers.get('content-length', 0))
|
| 52 |
+
download_progress[film_id] = {"total": total_size, "downloaded": 0, "status": "Downloading"}
|
| 53 |
|
| 54 |
os.makedirs(os.path.dirname(cache_path), exist_ok=True)
|
| 55 |
with open(cache_path, 'wb') as file, tqdm(total=total_size, unit='B', unit_scale=True, desc=cache_path) as pbar:
|
|
|
|
| 60 |
|
| 61 |
print(f'File cached to {cache_path} successfully.')
|
| 62 |
update_film_store_json(title, cache_path)
|
| 63 |
+
download_progress[film_id]["status"] = "Completed"
|
| 64 |
except RequestException as e:
|
| 65 |
print(f"Error downloading file: {e}")
|
| 66 |
+
download_progress[film_id]["status"] = "Failed"
|
| 67 |
except IOError as e:
|
| 68 |
print(f"Error writing file {cache_path}: {e}")
|
| 69 |
+
download_progress[film_id]["status"] = "Failed"
|
| 70 |
finally:
|
| 71 |
+
# Instead of deleting the progress, we mark it as complete or failed
|
| 72 |
+
if download_progress[film_id]["status"] != "Downloading":
|
| 73 |
+
del download_progress[film_id]
|
| 74 |
|
| 75 |
def get_download_progress(film_id):
|
| 76 |
"""
|
|
|
|
| 80 |
film_id (str): The unique identifier for the film download.
|
| 81 |
|
| 82 |
Returns:
|
| 83 |
+
dict: A dictionary containing the total size, downloaded size, progress percentage, and status.
|
| 84 |
"""
|
| 85 |
if film_id in download_progress:
|
| 86 |
total = download_progress[film_id]["total"]
|
| 87 |
downloaded = download_progress[film_id]["downloaded"]
|
| 88 |
+
status = download_progress[film_id].get("status", "In Progress")
|
| 89 |
+
progress = (downloaded / total) * 100 if total > 0 else 0
|
| 90 |
+
return {"total": total, "downloaded": downloaded, "progress": progress, "status": status}
|
| 91 |
+
return {"total": 0, "downloaded": 0, "progress": 0, "status": "Not Found"}
|
| 92 |
|
| 93 |
def update_film_store_json(title, cache_path):
|
| 94 |
"""
|
|
|
|
| 111 |
json.dump(film_store_data, json_file, indent=2)
|
| 112 |
print(f'Film store updated with {title}.')
|
| 113 |
|
|
|
|
| 114 |
def get_file_structure(repo, token, path="", proxies=None):
|
| 115 |
"""
|
| 116 |
Fetches the file structure of a specified Hugging Face repository.
|