Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import HfApi
|
| 3 |
import uuid
|
| 4 |
from slugify import slugify
|
| 5 |
import os
|
|
@@ -432,24 +432,30 @@ if __name__ == "__main__":
|
|
| 432 |
"summary": f"Smart template created for {repo_name}"
|
| 433 |
}
|
| 434 |
|
| 435 |
-
def clone(repo_git, repo_hf, sdk_type, skip_lfs, enable_smart_generation):
|
| 436 |
folder = str(uuid.uuid4())
|
| 437 |
|
| 438 |
-
|
| 439 |
if not hf_token:
|
| 440 |
-
|
|
|
|
|
|
|
|
|
|
| 441 |
return
|
| 442 |
|
| 443 |
try:
|
| 444 |
yield "๐ Starting clone process..."
|
| 445 |
|
| 446 |
-
|
| 447 |
try:
|
|
|
|
|
|
|
| 448 |
user_info = api.whoami()
|
| 449 |
username = user_info["name"]
|
| 450 |
-
yield f"โ
Authenticated as: {username}"
|
| 451 |
except Exception as e:
|
| 452 |
-
yield f"โ
|
|
|
|
| 453 |
return
|
| 454 |
|
| 455 |
# URL ์ ๊ทํ ๋ฐ ๊ฒ์ฆ
|
|
@@ -1180,6 +1186,58 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(
|
|
| 1180 |
|
| 1181 |
with gr.Tabs(elem_classes="tabs"):
|
| 1182 |
with gr.Tab("๐ GitHub โ HF Space", elem_id="tab1"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1183 |
with gr.Row():
|
| 1184 |
with gr.Column(scale=5):
|
| 1185 |
with gr.Group(elem_classes="input-section"):
|
|
@@ -1233,25 +1291,40 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(
|
|
| 1233 |
show_copy_button=True
|
| 1234 |
)
|
| 1235 |
|
| 1236 |
-
#
|
| 1237 |
-
|
| 1238 |
-
gr.HTML("""
|
| 1239 |
-
<div style="background: #fef2f2; border: 1px solid #fecaca;
|
| 1240 |
-
|
| 1241 |
-
<span style="color: #
|
| 1242 |
-
|
| 1243 |
-
""")
|
| 1244 |
-
else:
|
| 1245 |
-
gr.HTML("""
|
| 1246 |
-
<div style="background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 12px; margin-top: 10px;">
|
| 1247 |
-
<span style="color: #16a34a; font-weight: 600;">โ
Ready:</span>
|
| 1248 |
-
<span style="color: #14532d;"> HF_TOKEN configured successfully</span>
|
| 1249 |
</div>
|
| 1250 |
""")
|
| 1251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1252 |
btn_to_hf.click(
|
| 1253 |
fn=clone,
|
| 1254 |
-
inputs=[repo_git, repo_hf, sdk_choices, skip_lfs, enable_smart_generation],
|
| 1255 |
outputs=output_to_hf
|
| 1256 |
)
|
| 1257 |
|
|
@@ -1330,16 +1403,61 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(
|
|
| 1330 |
</div>
|
| 1331 |
</div>
|
| 1332 |
|
| 1333 |
-
<div style="margin-top: 30px;">
|
| 1334 |
-
<h4 style="color: #334155;"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1335 |
<p>
|
| 1336 |
-
<code style="background: #e2e8f0; padding: 4px 8px; border-radius: 4px;">
|
| 1337 |
-
<code style="background: #e2e8f0; padding: 4px 8px; border-radius: 4px;">GitHub PAT</code> for HF โ GitHub |
|
| 1338 |
-
<code style="background: #e2e8f0; padding: 4px 8px; border-radius: 4px;">FIREWORKS_API_KEY</code> for AI features
|
| 1339 |
</p>
|
| 1340 |
</div>
|
| 1341 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1342 |
""")
|
| 1343 |
|
| 1344 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1345 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import HfApi, login
|
| 3 |
import uuid
|
| 4 |
from slugify import slugify
|
| 5 |
import os
|
|
|
|
| 432 |
"summary": f"Smart template created for {repo_name}"
|
| 433 |
}
|
| 434 |
|
| 435 |
+
def clone(repo_git, repo_hf, sdk_type, skip_lfs, enable_smart_generation, hf_token=None):
|
| 436 |
folder = str(uuid.uuid4())
|
| 437 |
|
| 438 |
+
# HF Token ์ฒ๋ฆฌ - ํ๊ฒฝ๋ณ์๋ณด๋ค ์
๋ ฅ๊ฐ ์ฐ์
|
| 439 |
if not hf_token:
|
| 440 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 441 |
+
|
| 442 |
+
if not hf_token:
|
| 443 |
+
yield "โ Error: HuggingFace token not provided. Please enter your token or use OAuth login."
|
| 444 |
return
|
| 445 |
|
| 446 |
try:
|
| 447 |
yield "๐ Starting clone process..."
|
| 448 |
|
| 449 |
+
# HuggingFace ๋ก๊ทธ์ธ ๋ฐ ์ธ์ฆ
|
| 450 |
try:
|
| 451 |
+
login(token=hf_token)
|
| 452 |
+
api = HfApi(token=hf_token)
|
| 453 |
user_info = api.whoami()
|
| 454 |
username = user_info["name"]
|
| 455 |
+
yield f"โ
Authenticated as HuggingFace user: @{username}"
|
| 456 |
except Exception as e:
|
| 457 |
+
yield f"โ HuggingFace authentication failed: {str(e)}"
|
| 458 |
+
yield "Please check your token or try OAuth login"
|
| 459 |
return
|
| 460 |
|
| 461 |
# URL ์ ๊ทํ ๋ฐ ๊ฒ์ฆ
|
|
|
|
| 1186 |
|
| 1187 |
with gr.Tabs(elem_classes="tabs"):
|
| 1188 |
with gr.Tab("๐ GitHub โ HF Space", elem_id="tab1"):
|
| 1189 |
+
# OAuth ๋ก๊ทธ์ธ ์น์
|
| 1190 |
+
with gr.Group(elem_classes="input-section", visible=True) as auth_section:
|
| 1191 |
+
gr.HTML("""
|
| 1192 |
+
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 1193 |
+
padding: 20px; border-radius: 10px; color: white; margin-bottom: 20px;">
|
| 1194 |
+
<h3 style="margin: 0 0 10px 0;">๐ HuggingFace Authentication Required</h3>
|
| 1195 |
+
<p style="margin: 5px 0;">Choose one of the following methods to authenticate:</p>
|
| 1196 |
+
</div>
|
| 1197 |
+
""")
|
| 1198 |
+
|
| 1199 |
+
with gr.Row():
|
| 1200 |
+
with gr.Column():
|
| 1201 |
+
gr.Markdown("""
|
| 1202 |
+
### Option 1: OAuth Login (Recommended)
|
| 1203 |
+
Click the button below to login with your HuggingFace account
|
| 1204 |
+
""")
|
| 1205 |
+
gr.HTML("""
|
| 1206 |
+
<a href="https://huggingface.co/login?next=%2Fsettings%2Ftokens" target="_blank">
|
| 1207 |
+
<button style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 1208 |
+
color: white; border: none; padding: 12px 24px;
|
| 1209 |
+
border-radius: 8px; font-size: 16px; font-weight: 600;
|
| 1210 |
+
cursor: pointer; width: 100%; margin: 10px 0;">
|
| 1211 |
+
๐ค Login with HuggingFace
|
| 1212 |
+
</button>
|
| 1213 |
+
</a>
|
| 1214 |
+
""")
|
| 1215 |
+
gr.Markdown("""
|
| 1216 |
+
After login:
|
| 1217 |
+
1. Go to [Settings โ Access Tokens](https://huggingface.co/settings/tokens)
|
| 1218 |
+
2. Create a new token with **write** access
|
| 1219 |
+
3. Copy and paste it below
|
| 1220 |
+
""")
|
| 1221 |
+
|
| 1222 |
+
with gr.Column():
|
| 1223 |
+
gr.Markdown("""
|
| 1224 |
+
### Option 2: Direct Token Input
|
| 1225 |
+
If you already have a token, enter it here
|
| 1226 |
+
""")
|
| 1227 |
+
hf_token_input = gr.Textbox(
|
| 1228 |
+
label="HuggingFace Token",
|
| 1229 |
+
type="password",
|
| 1230 |
+
placeholder="hf_xxxxxxxxxxxxxxxxxxxxx",
|
| 1231 |
+
info="Your HF token with write access"
|
| 1232 |
+
)
|
| 1233 |
+
gr.Markdown("""
|
| 1234 |
+
**Need a token?**
|
| 1235 |
+
1. Visit [HuggingFace Tokens](https://huggingface.co/settings/tokens)
|
| 1236 |
+
2. Click "New token"
|
| 1237 |
+
3. Give it a name and select "write" role
|
| 1238 |
+
4. Copy the token here
|
| 1239 |
+
""")
|
| 1240 |
+
|
| 1241 |
with gr.Row():
|
| 1242 |
with gr.Column(scale=5):
|
| 1243 |
with gr.Group(elem_classes="input-section"):
|
|
|
|
| 1291 |
show_copy_button=True
|
| 1292 |
)
|
| 1293 |
|
| 1294 |
+
# Token ์ํ ํ์
|
| 1295 |
+
with gr.Row():
|
| 1296 |
+
token_status = gr.HTML("""
|
| 1297 |
+
<div id="token-status" style="background: #fef2f2; border: 1px solid #fecaca;
|
| 1298 |
+
border-radius: 8px; padding: 12px; margin-top: 10px;">
|
| 1299 |
+
<span style="color: #dc2626; font-weight: 600;">โ ๏ธ Status:</span>
|
| 1300 |
+
<span style="color: #7f1d1d;"> No token provided. Please login or enter your token above.</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1301 |
</div>
|
| 1302 |
""")
|
| 1303 |
|
| 1304 |
+
# Token ์
๋ ฅ์ ์ํ ์
๋ฐ์ดํธ
|
| 1305 |
+
def update_token_status(token):
|
| 1306 |
+
if token and token.strip():
|
| 1307 |
+
return """
|
| 1308 |
+
<div style="background: #f0fdf4; border: 1px solid #bbf7d0;
|
| 1309 |
+
border-radius: 8px; padding: 12px; margin-top: 10px;">
|
| 1310 |
+
<span style="color: #16a34a; font-weight: 600;">โ
Status:</span>
|
| 1311 |
+
<span style="color: #14532d;"> Token provided. Ready to deploy!</span>
|
| 1312 |
+
</div>
|
| 1313 |
+
"""
|
| 1314 |
+
else:
|
| 1315 |
+
return """
|
| 1316 |
+
<div style="background: #fef2f2; border: 1px solid #fecaca;
|
| 1317 |
+
border-radius: 8px; padding: 12px; margin-top: 10px;">
|
| 1318 |
+
<span style="color: #dc2626; font-weight: 600;">โ ๏ธ Status:</span>
|
| 1319 |
+
<span style="color: #7f1d1d;"> No token provided. Please login or enter your token above.</span>
|
| 1320 |
+
</div>
|
| 1321 |
+
"""
|
| 1322 |
+
|
| 1323 |
+
hf_token_input.change(update_token_status, inputs=[hf_token_input], outputs=[token_status])
|
| 1324 |
+
|
| 1325 |
btn_to_hf.click(
|
| 1326 |
fn=clone,
|
| 1327 |
+
inputs=[repo_git, repo_hf, sdk_choices, skip_lfs, enable_smart_generation, hf_token_input],
|
| 1328 |
outputs=output_to_hf
|
| 1329 |
)
|
| 1330 |
|
|
|
|
| 1403 |
</div>
|
| 1404 |
</div>
|
| 1405 |
|
| 1406 |
+
<div style="margin-top: 30px; background: #f1f5f9; padding: 20px; border-radius: 10px;">
|
| 1407 |
+
<h4 style="color: #334155;">๐ Authentication Setup</h4>
|
| 1408 |
+
|
| 1409 |
+
<div style="text-align: left; max-width: 600px; margin: auto;">
|
| 1410 |
+
<h5 style="color: #667eea;">For GitHub โ HuggingFace:</h5>
|
| 1411 |
+
<ol style="line-height: 1.8;">
|
| 1412 |
+
<li>Click "Login with HuggingFace" button above</li>
|
| 1413 |
+
<li>Authorize the application if prompted</li>
|
| 1414 |
+
<li>Go to <a href="https://huggingface.co/settings/tokens" target="_blank">Settings โ Access Tokens</a></li>
|
| 1415 |
+
<li>Create a new token with <strong>write</strong> access</li>
|
| 1416 |
+
<li>Copy and paste the token in the input field</li>
|
| 1417 |
+
</ol>
|
| 1418 |
+
|
| 1419 |
+
<h5 style="color: #667eea; margin-top: 20px;">For HuggingFace โ GitHub:</h5>
|
| 1420 |
+
<ol style="line-height: 1.8;">
|
| 1421 |
+
<li>Go to <a href="https://github.com/settings/tokens" target="_blank">GitHub Settings โ Tokens</a></li>
|
| 1422 |
+
<li>Generate new token (classic)</li>
|
| 1423 |
+
<li>Select <code>repo</code> scope</li>
|
| 1424 |
+
<li>Copy and use in the GitHub export tab</li>
|
| 1425 |
+
</ol>
|
| 1426 |
+
</div>
|
| 1427 |
+
</div>
|
| 1428 |
+
|
| 1429 |
+
<div style="margin-top: 20px;">
|
| 1430 |
+
<h4 style="color: #334155;">Optional API Keys</h4>
|
| 1431 |
<p>
|
| 1432 |
+
<code style="background: #e2e8f0; padding: 4px 8px; border-radius: 4px;">FIREWORKS_API_KEY</code> - For AI-powered app generation
|
|
|
|
|
|
|
| 1433 |
</p>
|
| 1434 |
</div>
|
| 1435 |
</div>
|
| 1436 |
+
|
| 1437 |
+
## README.md Configuration
|
| 1438 |
+
|
| 1439 |
+
When deploying to HuggingFace Spaces, the following YAML header will be automatically added to your README.md:
|
| 1440 |
+
|
| 1441 |
+
```yaml
|
| 1442 |
+
---
|
| 1443 |
+
title: Your Space Title
|
| 1444 |
+
emoji: ๐
|
| 1445 |
+
colorFrom: blue
|
| 1446 |
+
colorTo: green
|
| 1447 |
+
sdk: gradio # or streamlit, docker, static
|
| 1448 |
+
sdk_version: "5.35.0"
|
| 1449 |
+
app_file: app.py
|
| 1450 |
+
pinned: false
|
| 1451 |
+
---
|
| 1452 |
+
```
|
| 1453 |
+
|
| 1454 |
+
This configuration ensures your Space runs correctly on HuggingFace infrastructure.
|
| 1455 |
""")
|
| 1456 |
|
| 1457 |
if __name__ == "__main__":
|
| 1458 |
+
# OAuth ํ๊ฒฝ ์ค์ ์ฒดํฌ
|
| 1459 |
+
if os.getenv("SPACE_ID"):
|
| 1460 |
+
print("Running on HuggingFace Spaces")
|
| 1461 |
+
print("OAuth callback URL: https://huggingface.co/spaces/" + os.getenv("SPACE_ID"))
|
| 1462 |
+
|
| 1463 |
demo.launch()
|