arj7192 commited on
Commit
c61fea6
·
verified ·
1 Parent(s): 26129bd

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -48
app.py CHANGED
@@ -22,62 +22,35 @@ from pipeline_flux_controlnet_inpaint import FluxControlNetInpaintingPipeline
22
  import huggingface_hub
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
- url = f"https://api.github.com/repos/{repo}/releases/tags/{release_tag}"
31
- headers = {"Authorization": f"token {token}"}
32
- print(f"Fetching release info from: {url}") # Debug URL
33
-
34
- response = requests.get(url, headers=headers)
35
- print(f"Status Code: {response.status_code}") # Debug status code
36
- print(f"Response Content: {response.json()}") # Debug API response
37
-
38
- if response.status_code == 200:
39
- release_data = response.json()
40
- # Find the asset by name
41
- asset = next((a for a in release_data['assets'] if a['name'] == asset_name), None)
42
- if not asset:
43
- raise Exception(f"Asset {asset_name} not found in release {release_tag}.")
44
-
45
- # Download the asset
46
- download_url = asset['browser_download_url']
47
- print(f"Downloading asset from: {download_url}") # Debug download URL
48
-
49
- download_response = requests.get(download_url, headers=headers, stream=True)
50
- if download_response.status_code == 200:
51
- os.makedirs(os.path.dirname(destination), exist_ok=True)
52
- with open(destination, 'wb') as f:
53
- for chunk in download_response.iter_content(chunk_size=1024):
54
- f.write(chunk)
55
- print(f"Downloaded {asset_name} to {destination}")
56
- else:
57
- raise Exception(f"Failed to download {asset_name}. Status code: {download_response.status_code}")
58
- else:
59
- raise Exception(f"Failed to fetch release {release_tag}. Status code: {response.status_code}")
60
-
61
-
62
-
63
- # Example: Define GitHub repo and file paths
64
- repo_name = "arj7192/NativDemoLocal"
65
- release_tag = "v1"
66
- github_files = {
67
- "speech_bubble_model.pt": "speech_bubble_model.pt",
68
- "craft_mlt_25k.pth": "craft_mlt_25k.pth",
69
- "english_g2.pth": "english_g2.pth",
70
- "korean_g2.pth": "korean_g2.pth",
71
- "latin_g2.pth": "latin_g2.pth",
72
- "zh_sim_g2.pth": "zh_sim_g2.pth",
73
  }
74
 
75
  token = os.getenv("HF_GITHUB_TOKEN")
76
 
77
  # Download each file
78
- for filename, repo_path in github_files.items():
79
- destination_path = f"{filename}"
80
- download_release_asset(repo_name, release_tag, filename, destination_path, token)
81
 
82
  bubble_detection_model = YOLO("speech_bubble_model.pt")
83
 
 
22
  import huggingface_hub
23
  huggingface_hub.login(os.getenv('HF_TOKEN_FLUX'))
24
 
25
+ import gdown
26
 
27
+ def download_from_gdrive(file_id, destination):
28
  """
29
+ Download a file from Google Drive using gdown.
30
+
31
+ Args:
32
+ file_id (str): The Google Drive file ID.
33
+ destination (str): Local path to save the downloaded file.
34
  """
35
+ url = f"https://drive.google.com/uc?id={file_id}"
36
+ gdown.download(url, destination, quiet=False)
37
+ print(f"File downloaded to {destination}")
38
+
39
+
40
+ files = {
41
+ "speech_bubble_model": "speech_bubble_model.pt",
42
+ "craft_mlt_25k": "craft_mlt_25k.pth",
43
+ "english_g2": "english_g2.pth",
44
+ "korean_g2": "korean_g2.pth",
45
+ "latin_g2": "latin_g2.pth",
46
+ "zh_sim_g2": "zh_sim_g2.pth",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
 
49
  token = os.getenv("HF_GITHUB_TOKEN")
50
 
51
  # Download each file
52
+ for filename, destination_path in files.items():
53
+ download_from_gdrive(os.getenv(filename), destination_path)
 
54
 
55
  bubble_detection_model = YOLO("speech_bubble_model.pt")
56