openfree commited on
Commit
fe395b2
ยท
verified ยท
1 Parent(s): b99342b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -18,6 +18,11 @@ def launch_deploy_oauth(repo_url, private, profile: gr.OAuthProfile | None):
18
  ์ƒ๋‹จ์˜ 'Sign in with Hugging Face' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด ๋กœ๊ทธ์ธํ•ด์ฃผ์„ธ์š”."""
19
 
20
  hf_token = profile.token
 
 
 
 
 
21
  return _deploy_space(repo_url, hf_token, private)
22
 
23
  def launch_deploy_manual(repo_url, hf_token, private):
@@ -27,10 +32,30 @@ def launch_deploy_manual(repo_url, hf_token, private):
27
 
28
  Hugging Face Write ํ† ํฐ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."""
29
 
 
 
 
 
 
 
 
 
 
 
30
  return _deploy_space(repo_url, hf_token, private)
31
 
32
  def _deploy_space(repo_url, hf_token, private):
33
  """๊ณตํ†ต ๋ฐฐํฌ ๋กœ์ง"""
 
 
 
 
 
 
 
 
 
 
34
  # ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋Œ€์‹  ์ง์ ‘ ํ† ํฐ ์ „๋‹ฌ
35
  try:
36
  link = deploy(repo_url, hf_token, private=private)
@@ -56,6 +81,16 @@ Space Settings > Variables and secrets์—์„œ `BAPI_TOKEN`์„ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
56
 
57
  Space Settings > Variables and secrets์—์„œ `FRIENDLI_TOKEN`์„ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
58
  [Friendli AI](https://friendli.ai/) ์—์„œ API ํ‚ค๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."""
 
 
 
 
 
 
 
 
 
 
59
  else:
60
  return f"""### โŒ ๋ฐฐํฌ ์˜ค๋ฅ˜
61
 
 
18
  ์ƒ๋‹จ์˜ 'Sign in with Hugging Face' ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด ๋กœ๊ทธ์ธํ•ด์ฃผ์„ธ์š”."""
19
 
20
  hf_token = profile.token
21
+
22
+ # ํ† ํฐ ์ •๋ฆฌ (OAuth์—์„œ๋„ ์•ˆ์ „ํ•˜๊ฒŒ)
23
+ if hf_token:
24
+ hf_token = hf_token.strip()
25
+
26
  return _deploy_space(repo_url, hf_token, private)
27
 
28
  def launch_deploy_manual(repo_url, hf_token, private):
 
32
 
33
  Hugging Face Write ํ† ํฐ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."""
34
 
35
+ # ํ† ํฐ ์ •๋ฆฌ (๊ณต๋ฐฑ, ์ค„๋ฐ”๊ฟˆ ์ œ๊ฑฐ)
36
+ hf_token = hf_token.strip()
37
+
38
+ # ํ† ํฐ ํ˜•์‹ ๊ฒ€์ฆ
39
+ if not hf_token.startswith("hf_"):
40
+ return """### โŒ ์ž˜๋ชป๋œ ํ† ํฐ ํ˜•์‹
41
+
42
+ ํ† ํฐ์€ 'hf_'๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
43
+ https://huggingface.co/settings/tokens ์—์„œ Write ๊ถŒํ•œ ํ† ํฐ์„ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”."""
44
+
45
  return _deploy_space(repo_url, hf_token, private)
46
 
47
  def _deploy_space(repo_url, hf_token, private):
48
  """๊ณตํ†ต ๋ฐฐํฌ ๋กœ์ง"""
49
+ # URL ์ •๋ฆฌ
50
+ repo_url = repo_url.strip()
51
+
52
+ # URL ๊ฒ€์ฆ
53
+ if not repo_url.startswith(("https://github.com/", "http://github.com/", "[email protected]:")):
54
+ return """### โŒ ์ž˜๋ชป๋œ Repository URL
55
+
56
+ GitHub URL ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
57
+ ์˜ˆ์‹œ: https://github.com/username/repository"""
58
+
59
  # ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋Œ€์‹  ์ง์ ‘ ํ† ํฐ ์ „๋‹ฌ
60
  try:
61
  link = deploy(repo_url, hf_token, private=private)
 
81
 
82
  Space Settings > Variables and secrets์—์„œ `FRIENDLI_TOKEN`์„ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
83
  [Friendli AI](https://friendli.ai/) ์—์„œ API ํ‚ค๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."""
84
+ elif "Invalid header value" in error_msg:
85
+ return """### โŒ ํ† ํฐ ์˜ค๋ฅ˜
86
+
87
+ ํ† ํฐ์— ์ž˜๋ชป๋œ ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
88
+ ํ† ํฐ์„ ๋‹ค์‹œ ๋ณต์‚ฌํ•˜์—ฌ ๊ณต๋ฐฑ์ด๋‚˜ ์ค„๋ฐ”๊ฟˆ ์—†์ด ๋ถ™์—ฌ๋„ฃ์–ด์ฃผ์„ธ์š”."""
89
+ elif "401" in error_msg or "403" in error_msg:
90
+ return """### โŒ ์ธ์ฆ ์‹คํŒจ
91
+
92
+ ํ† ํฐ์ด ์œ ํšจํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ Write ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.
93
+ https://huggingface.co/settings/tokens ์—์„œ Write ๊ถŒํ•œ์ด ์žˆ๋Š” ํ† ํฐ์ธ์ง€ ํ™•์ธํ•ด์ฃผ์„ธ์š”."""
94
  else:
95
  return f"""### โŒ ๋ฐฐํฌ ์˜ค๋ฅ˜
96