Upload app.py
Browse files
app.py
CHANGED
@@ -23,37 +23,51 @@ import huggingface_hub
|
|
23 |
huggingface_hub.login(os.getenv('HF_TOKEN_FLUX'))
|
24 |
|
25 |
|
26 |
-
def
|
27 |
"""
|
28 |
-
Download a file from a
|
29 |
-
|
30 |
Args:
|
31 |
repo (str): The GitHub repository in the format "owner/repo".
|
32 |
-
|
|
|
33 |
destination (str): The local file path to save the downloaded file.
|
34 |
token (str): The GitHub Personal Access Token.
|
35 |
-
|
36 |
Returns:
|
37 |
None
|
38 |
"""
|
39 |
-
|
|
|
40 |
headers = {"Authorization": f"token {token}"}
|
41 |
response = requests.get(url, headers=headers)
|
42 |
-
|
43 |
if response.status_code == 200:
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
os.makedirs(os.path.dirname(destination), exist_ok=True)
|
47 |
with open(destination, 'wb') as f:
|
48 |
-
|
49 |
-
|
|
|
50 |
else:
|
51 |
-
raise Exception(f"
|
52 |
else:
|
53 |
-
raise Exception(f"Failed to
|
|
|
54 |
|
55 |
# Example: Define GitHub repo and file paths
|
56 |
repo_name = "arj7192/NativDemoLocal"
|
|
|
57 |
github_files = {
|
58 |
"speech_bubble_model.pt": "speech_bubble_model.pt",
|
59 |
"craft_mlt_25k.pth": "craft_mlt_25k.pth",
|
@@ -68,7 +82,7 @@ token = os.getenv("HF_GITHUB_TOKEN")
|
|
68 |
# Download each file
|
69 |
for filename, repo_path in github_files.items():
|
70 |
destination_path = f"{filename}"
|
71 |
-
|
72 |
|
73 |
bubble_detection_model = YOLO("speech_bubble_model.pt")
|
74 |
|
|
|
23 |
huggingface_hub.login(os.getenv('HF_TOKEN_FLUX'))
|
24 |
|
25 |
|
26 |
+
def download_release_asset(repo, release_tag, asset_name, destination, token):
|
27 |
"""
|
28 |
+
Download a file from a GitHub Release.
|
29 |
+
|
30 |
Args:
|
31 |
repo (str): The GitHub repository in the format "owner/repo".
|
32 |
+
release_tag (str): The release tag (e.g., "v1.0.0").
|
33 |
+
asset_name (str): The name of the file in the release.
|
34 |
destination (str): The local file path to save the downloaded file.
|
35 |
token (str): The GitHub Personal Access Token.
|
36 |
+
|
37 |
Returns:
|
38 |
None
|
39 |
"""
|
40 |
+
# Fetch release assets
|
41 |
+
url = f"https://api.github.com/repos/{repo}/releases/tags/{release_tag}"
|
42 |
headers = {"Authorization": f"token {token}"}
|
43 |
response = requests.get(url, headers=headers)
|
44 |
+
|
45 |
if response.status_code == 200:
|
46 |
+
release_data = response.json()
|
47 |
+
# Find the asset by name
|
48 |
+
asset = next((a for a in release_data['assets'] if a['name'] == asset_name), None)
|
49 |
+
if not asset:
|
50 |
+
raise Exception(f"Asset {asset_name} not found in release {release_tag}.")
|
51 |
+
|
52 |
+
# Download the asset
|
53 |
+
download_url = asset['browser_download_url']
|
54 |
+
download_response = requests.get(download_url, headers=headers, stream=True)
|
55 |
+
|
56 |
+
if download_response.status_code == 200:
|
57 |
os.makedirs(os.path.dirname(destination), exist_ok=True)
|
58 |
with open(destination, 'wb') as f:
|
59 |
+
for chunk in download_response.iter_content(chunk_size=1024):
|
60 |
+
f.write(chunk)
|
61 |
+
print(f"Downloaded {asset_name} to {destination}")
|
62 |
else:
|
63 |
+
raise Exception(f"Failed to download {asset_name}. Status code: {download_response.status_code}")
|
64 |
else:
|
65 |
+
raise Exception(f"Failed to fetch release {release_tag}. Status code: {response.status_code}")
|
66 |
+
|
67 |
|
68 |
# Example: Define GitHub repo and file paths
|
69 |
repo_name = "arj7192/NativDemoLocal"
|
70 |
+
release_tag = "v1"
|
71 |
github_files = {
|
72 |
"speech_bubble_model.pt": "speech_bubble_model.pt",
|
73 |
"craft_mlt_25k.pth": "craft_mlt_25k.pth",
|
|
|
82 |
# Download each file
|
83 |
for filename, repo_path in github_files.items():
|
84 |
destination_path = f"{filename}"
|
85 |
+
download_release_asset(repo_name, release_tag, filename, destination_path, token)
|
86 |
|
87 |
bubble_detection_model = YOLO("speech_bubble_model.pt")
|
88 |
|