Spaces:
Running
Running
update
Browse files
README.md
CHANGED
@@ -80,11 +80,18 @@ AnyCoder now includes one-click deployment to Hugging Face Spaces! This feature
|
|
80 |
|
81 |
### How to Deploy
|
82 |
|
83 |
-
1. **Login**: Click the "Sign in with Hugging Face" button in the sidebar
|
84 |
-
2. **
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
**Note**: You need to be logged in with your Hugging Face account to deploy. This ensures that:
|
90 |
- Deployments are created under your own account namespace
|
@@ -93,6 +100,16 @@ AnyCoder now includes one-click deployment to Hugging Face Spaces! This feature
|
|
93 |
|
94 |
**Technical Note**: The deployment uses your personal OAuth token to create spaces under your account, ensuring full security and ownership of your deployed applications.
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
### What Gets Deployed
|
97 |
|
98 |
- **Complete HTML Application**: Your generated code wrapped in a professional template
|
|
|
80 |
|
81 |
### How to Deploy
|
82 |
|
83 |
+
1. **Login**: Click the "Sign in with Hugging Face" button in the sidebar
|
84 |
+
2. **Authorize Permissions**: When the authorization page appears, make sure to grant ALL the requested permissions:
|
85 |
+
- β
**read-repos** - Read access to repositories
|
86 |
+
- β
**write-repos** - Write access to create repositories
|
87 |
+
- β
**manage-repos** - Manage repository settings
|
88 |
+
3. **Complete Authorization**: Click "Authorize" to complete the login
|
89 |
+
4. **Generate Code**: Generate some HTML code using the AI
|
90 |
+
5. **Enter Title**: In the sidebar, enter a title for your space (e.g., "My Todo App")
|
91 |
+
6. **Deploy**: Click the "π Deploy to Space" button
|
92 |
+
7. **Share**: Get a shareable URL for your deployed application
|
93 |
+
|
94 |
+
**Important**: You must grant ALL three permissions during the OAuth authorization process. If you only grant partial permissions, deployment will fail.
|
95 |
|
96 |
**Note**: You need to be logged in with your Hugging Face account to deploy. This ensures that:
|
97 |
- Deployments are created under your own account namespace
|
|
|
100 |
|
101 |
**Technical Note**: The deployment uses your personal OAuth token to create spaces under your account, ensuring full security and ownership of your deployed applications.
|
102 |
|
103 |
+
### Troubleshooting Deployment Issues
|
104 |
+
|
105 |
+
If you encounter permission errors during deployment:
|
106 |
+
|
107 |
+
1. **Check Permissions**: Make sure you granted all three required permissions during login
|
108 |
+
2. **Logout and Login Again**: Click logout and sign in again, ensuring all permissions are granted
|
109 |
+
3. **Account Status**: Verify your Hugging Face account allows repository creation
|
110 |
+
4. **Network Issues**: Check your internet connection and try again
|
111 |
+
5. **Contact Support**: If issues persist, contact Hugging Face support
|
112 |
+
|
113 |
### What Gets Deployed
|
114 |
|
115 |
- **Complete HTML Application**: Your generated code wrapped in a professional template
|
app.py
CHANGED
@@ -185,6 +185,39 @@ if TAVILY_API_KEY:
|
|
185 |
print(f"Failed to initialize Tavily client: {e}")
|
186 |
tavily_client = None
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
# Deployment functions
|
189 |
def create_space_from_html(title: str, html_content: str, prompts: List[str] = None, user_token: str = None, username: str = None) -> Dict:
|
190 |
"""
|
@@ -430,15 +463,15 @@ Visit: https://huggingface.co/spaces/{repo_name}
|
|
430 |
"message": f"Failed to create space: {error_msg}"
|
431 |
}
|
432 |
|
433 |
-
def deploy_to_space(title: str, html_content: str, history: History, oauth_profile: gr.OAuthProfile = None, oauth_token: gr.OAuthToken = None) -> str:
|
434 |
"""
|
435 |
Deploy the generated HTML to a Hugging Face Space
|
436 |
"""
|
437 |
if not title or not title.strip():
|
438 |
-
return "β Please enter a title for your space."
|
439 |
|
440 |
if not html_content or not html_content.strip():
|
441 |
-
return "β No HTML content to deploy. Please generate some code first."
|
442 |
|
443 |
# Check if user is authenticated
|
444 |
if not oauth_profile or not oauth_token:
|
@@ -462,7 +495,7 @@ To deploy your application, you need to be logged in with your Hugging Face acco
|
|
462 |
**Note:** Make sure to grant all the requested permissions when authorizing the application.
|
463 |
|
464 |
---
|
465 |
-
*Please log in and try again.*"""
|
466 |
|
467 |
# Get user information from OAuth profile
|
468 |
username = oauth_profile.name
|
@@ -480,6 +513,51 @@ To deploy your application, you need to be logged in with your Hugging Face acco
|
|
480 |
print(f"Debug: OAuth profile attributes: {dir(oauth_profile) if oauth_profile else 'None'}")
|
481 |
print(f"Debug: OAuth token attributes: {dir(oauth_token) if oauth_token else 'None'}")
|
482 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
483 |
# Validate token format
|
484 |
if not user_token or not user_token.startswith('hf_'):
|
485 |
return """β **Invalid Token Format**
|
@@ -495,7 +573,7 @@ The OAuth token appears to be invalid or in the wrong format. Please try logging
|
|
495 |
**Note:** Make sure you authorize all the required permissions when logging in.
|
496 |
|
497 |
---
|
498 |
-
*Please try logging in again.*"""
|
499 |
|
500 |
# Test the token by making a simple API call
|
501 |
try:
|
@@ -507,27 +585,73 @@ The OAuth token appears to be invalid or in the wrong format. Please try logging
|
|
507 |
try:
|
508 |
repos = test_api.list_repos(author=username, token=user_token)
|
509 |
print(f"Debug: User has {len(list(repos))} repositories")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
510 |
except Exception as repo_error:
|
511 |
print(f"Debug: Could not list repos: {repo_error}")
|
512 |
-
|
|
|
|
|
|
|
|
|
513 |
|
514 |
Your Hugging Face account doesn't have the necessary permissions to create spaces. This could be because:
|
515 |
|
516 |
-
1. You didn't grant all the required permissions during login
|
517 |
-
2. Your account has restrictions on creating repositories
|
518 |
-
3. The OAuth token doesn't include the necessary scopes
|
|
|
|
|
|
|
|
|
|
|
519 |
|
520 |
**Steps to fix:**
|
521 |
-
1. Click the logout button in the sidebar
|
522 |
-
2. Click "Sign in with Hugging Face" again
|
523 |
-
3.
|
524 |
-
- read-repos
|
525 |
-
- write-repos
|
526 |
-
- manage-repos
|
527 |
-
4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
528 |
|
529 |
---
|
530 |
-
*Please
|
531 |
|
532 |
except Exception as token_error:
|
533 |
print(f"Debug: Token test failed: {token_error}")
|
@@ -546,7 +670,7 @@ The OAuth token could not be validated. This could be because:
|
|
546 |
4. Try deploying again
|
547 |
|
548 |
---
|
549 |
-
*Please log in again.*"""
|
550 |
|
551 |
# Extract prompts from history
|
552 |
prompts = []
|
@@ -554,6 +678,87 @@ The OAuth token could not be validated. This could be because:
|
|
554 |
if isinstance(user_msg, str) and user_msg.strip():
|
555 |
prompts.append(user_msg.strip())
|
556 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
# Use user's OAuth token to create space under their account
|
558 |
result = create_space_from_html(title.strip(), html_content, prompts, user_token, username)
|
559 |
|
@@ -571,7 +776,7 @@ Your application is now live on Hugging Face Spaces under your account. You can
|
|
571 |
- Manage your space from your Hugging Face dashboard
|
572 |
|
573 |
---
|
574 |
-
*Generated with β€οΈ using AnyCoder*"""
|
575 |
else:
|
576 |
return f"""β **Deployment failed**
|
577 |
|
@@ -584,7 +789,7 @@ Your application is now live on Hugging Face Spaces under your account. You can
|
|
584 |
- Make sure your Hugging Face account has the necessary permissions
|
585 |
|
586 |
---
|
587 |
-
*Please try again or contact support if the issue persists.*"""
|
588 |
|
589 |
def history_to_messages(history: History, system: str) -> Messages:
|
590 |
messages = [{'role': 'system', 'content': system}]
|
@@ -658,6 +863,20 @@ def history_render(history: History):
|
|
658 |
def clear_history():
|
659 |
return [], [], None, "" # Empty lists for both tuple format and chatbot messages, None for file, empty string for website URL
|
660 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
661 |
def update_image_input_visibility(model):
|
662 |
"""Update image input visibility based on selected model"""
|
663 |
is_ernie_vl = model.get("id") == "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT"
|
@@ -1325,6 +1544,8 @@ with gr.Blocks(
|
|
1325 |
# OAuth components are automatically injected as function parameters
|
1326 |
# when using gr.LoginButton() - no need to create them separately
|
1327 |
|
|
|
|
|
1328 |
# Main input section
|
1329 |
input = gr.Textbox(
|
1330 |
label="What would you like to build?",
|
@@ -1415,6 +1636,12 @@ with gr.Blocks(
|
|
1415 |
else:
|
1416 |
gr.Markdown("β
Web search available")
|
1417 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1418 |
# Hidden elements for functionality
|
1419 |
model_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[0]['name']}", visible=False)
|
1420 |
|
@@ -1461,15 +1688,16 @@ with gr.Blocks(
|
|
1461 |
### Prerequisites
|
1462 |
1. **Login Required**: You must be logged in with your Hugging Face account
|
1463 |
2. **Permissions**: Grant the following permissions when logging in:
|
1464 |
-
- read-repos
|
1465 |
-
- write-repos
|
1466 |
-
- manage-repos
|
1467 |
|
1468 |
### Steps to Deploy
|
1469 |
1. **Login**: Click "Sign in with Hugging Face" in the sidebar
|
1470 |
-
2. **
|
1471 |
-
3. **
|
1472 |
-
4. **
|
|
|
1473 |
|
1474 |
### What Happens
|
1475 |
- Your application will be deployed to Hugging Face Spaces under your account
|
@@ -1483,6 +1711,8 @@ If deployment fails:
|
|
1483 |
- Try logging out and logging back in
|
1484 |
- Check that your Hugging Face account can create repositories
|
1485 |
|
|
|
|
|
1486 |
---
|
1487 |
*Your application will be deployed to Hugging Face Spaces and you'll get a shareable URL!*""",
|
1488 |
label="Deployment Status"
|
@@ -1503,7 +1733,7 @@ If deployment fails:
|
|
1503 |
deploy_btn.click(
|
1504 |
deploy_to_space,
|
1505 |
inputs=[space_title_input, code_output, history],
|
1506 |
-
outputs=[deploy_output],
|
1507 |
api_name="deploy"
|
1508 |
)
|
1509 |
|
|
|
185 |
print(f"Failed to initialize Tavily client: {e}")
|
186 |
tavily_client = None
|
187 |
|
188 |
+
def validate_oauth_scopes(oauth_token) -> Tuple[bool, List[str]]:
|
189 |
+
"""
|
190 |
+
Validate that the OAuth token has the required scopes for creating spaces
|
191 |
+
Returns (is_valid, missing_scopes)
|
192 |
+
"""
|
193 |
+
required_scopes = ['read-repos', 'write-repos', 'manage-repos']
|
194 |
+
|
195 |
+
if not oauth_token:
|
196 |
+
return False, required_scopes
|
197 |
+
|
198 |
+
# Try to get scopes from the token object
|
199 |
+
token_scopes = []
|
200 |
+
|
201 |
+
# Check different ways scopes might be stored
|
202 |
+
if hasattr(oauth_token, 'scopes'):
|
203 |
+
token_scopes = oauth_token.scopes
|
204 |
+
elif hasattr(oauth_token, 'scope'):
|
205 |
+
token_scopes = oauth_token.scope.split(' ') if oauth_token.scope else []
|
206 |
+
elif hasattr(oauth_token, 'permissions'):
|
207 |
+
token_scopes = oauth_token.permissions
|
208 |
+
else:
|
209 |
+
# If we can't determine scopes, assume they're missing
|
210 |
+
return False, required_scopes
|
211 |
+
|
212 |
+
# Convert to list if it's a string
|
213 |
+
if isinstance(token_scopes, str):
|
214 |
+
token_scopes = token_scopes.split(' ')
|
215 |
+
|
216 |
+
# Check for required scopes
|
217 |
+
missing_scopes = [scope for scope in required_scopes if scope not in token_scopes]
|
218 |
+
|
219 |
+
return len(missing_scopes) == 0, missing_scopes
|
220 |
+
|
221 |
# Deployment functions
|
222 |
def create_space_from_html(title: str, html_content: str, prompts: List[str] = None, user_token: str = None, username: str = None) -> Dict:
|
223 |
"""
|
|
|
463 |
"message": f"Failed to create space: {error_msg}"
|
464 |
}
|
465 |
|
466 |
+
def deploy_to_space(title: str, html_content: str, history: History, oauth_profile: gr.OAuthProfile = None, oauth_token: gr.OAuthToken = None) -> Tuple[str, str]:
|
467 |
"""
|
468 |
Deploy the generated HTML to a Hugging Face Space
|
469 |
"""
|
470 |
if not title or not title.strip():
|
471 |
+
return "β Please enter a title for your space.", update_oauth_status(oauth_profile, oauth_token)
|
472 |
|
473 |
if not html_content or not html_content.strip():
|
474 |
+
return "β No HTML content to deploy. Please generate some code first.", update_oauth_status(oauth_profile, oauth_token)
|
475 |
|
476 |
# Check if user is authenticated
|
477 |
if not oauth_profile or not oauth_token:
|
|
|
495 |
**Note:** Make sure to grant all the requested permissions when authorizing the application.
|
496 |
|
497 |
---
|
498 |
+
*Please log in and try again.*""", update_oauth_status(oauth_profile, oauth_token)
|
499 |
|
500 |
# Get user information from OAuth profile
|
501 |
username = oauth_profile.name
|
|
|
513 |
print(f"Debug: OAuth profile attributes: {dir(oauth_profile) if oauth_profile else 'None'}")
|
514 |
print(f"Debug: OAuth token attributes: {dir(oauth_token) if oauth_token else 'None'}")
|
515 |
|
516 |
+
# Check OAuth token scopes if available
|
517 |
+
if hasattr(oauth_token, 'scopes'):
|
518 |
+
print(f"Debug: OAuth token scopes: {oauth_token.scopes}")
|
519 |
+
else:
|
520 |
+
print("Debug: OAuth token scopes not available")
|
521 |
+
|
522 |
+
# Check OAuth profile permissions if available
|
523 |
+
if hasattr(oauth_profile, 'permissions'):
|
524 |
+
print(f"Debug: OAuth profile permissions: {oauth_profile.permissions}")
|
525 |
+
else:
|
526 |
+
print("Debug: OAuth profile permissions not available")
|
527 |
+
|
528 |
+
# Validate OAuth scopes
|
529 |
+
scopes_valid, missing_scopes = validate_oauth_scopes(oauth_token)
|
530 |
+
print(f"Debug: OAuth scopes valid: {scopes_valid}")
|
531 |
+
print(f"Debug: Missing scopes: {missing_scopes}")
|
532 |
+
|
533 |
+
if not scopes_valid:
|
534 |
+
return f"""β **Missing OAuth Scopes**
|
535 |
+
|
536 |
+
Your OAuth token is missing the required permissions to create spaces.
|
537 |
+
|
538 |
+
**Missing Scopes:**
|
539 |
+
{chr(10).join([f"- `{scope}`" for scope in missing_scopes])}
|
540 |
+
|
541 |
+
**Required Scopes:**
|
542 |
+
- `read-repos` - Read access to repositories
|
543 |
+
- `write-repos` - Write access to create repositories
|
544 |
+
- `manage-repos` - Manage repository settings
|
545 |
+
|
546 |
+
**Steps to fix:**
|
547 |
+
1. **Logout**: Click the logout button in the sidebar
|
548 |
+
2. **Login Again**: Click "Sign in with Hugging Face" again
|
549 |
+
3. **Grant All Permissions**: When the authorization page appears, make sure to check ALL the requested permissions:
|
550 |
+
- β
read-repos
|
551 |
+
- β
write-repos
|
552 |
+
- β
manage-repos
|
553 |
+
4. **Complete Authorization**: Click "Authorize" to complete the login
|
554 |
+
5. **Try Deploying**: Try deploying again
|
555 |
+
|
556 |
+
**Important:** Make sure you see all three permissions checked on the authorization page before clicking "Authorize".
|
557 |
+
|
558 |
+
---
|
559 |
+
*Please log in again with full permissions.*""", update_oauth_status(oauth_profile, oauth_token)
|
560 |
+
|
561 |
# Validate token format
|
562 |
if not user_token or not user_token.startswith('hf_'):
|
563 |
return """β **Invalid Token Format**
|
|
|
573 |
**Note:** Make sure you authorize all the required permissions when logging in.
|
574 |
|
575 |
---
|
576 |
+
*Please try logging in again.*""", update_oauth_status(oauth_profile, oauth_token)
|
577 |
|
578 |
# Test the token by making a simple API call
|
579 |
try:
|
|
|
585 |
try:
|
586 |
repos = test_api.list_repos(author=username, token=user_token)
|
587 |
print(f"Debug: User has {len(list(repos))} repositories")
|
588 |
+
|
589 |
+
# Test if user can create repositories by checking their account type
|
590 |
+
try:
|
591 |
+
# Try to get user info to check account capabilities
|
592 |
+
user_info = test_api.whoami()
|
593 |
+
print(f"Debug: User info: {user_info}")
|
594 |
+
|
595 |
+
# Check if user has pro account or sufficient permissions
|
596 |
+
if user_info.get('type') == 'user':
|
597 |
+
print("Debug: User account type confirmed")
|
598 |
+
else:
|
599 |
+
print(f"Debug: User account type: {user_info.get('type', 'unknown')}")
|
600 |
+
|
601 |
+
except Exception as user_info_error:
|
602 |
+
print(f"Debug: Could not get detailed user info: {user_info_error}")
|
603 |
+
|
604 |
except Exception as repo_error:
|
605 |
print(f"Debug: Could not list repos: {repo_error}")
|
606 |
+
|
607 |
+
# Check if this is a scope/permission issue
|
608 |
+
error_msg = str(repo_error).lower()
|
609 |
+
if "403" in error_msg or "forbidden" in error_msg or "unauthorized" in error_msg:
|
610 |
+
return """β **Insufficient Permissions**
|
611 |
|
612 |
Your Hugging Face account doesn't have the necessary permissions to create spaces. This could be because:
|
613 |
|
614 |
+
1. **Missing OAuth Scopes**: You didn't grant all the required permissions during login
|
615 |
+
2. **Account Restrictions**: Your account has restrictions on creating repositories
|
616 |
+
3. **Token Scope Issues**: The OAuth token doesn't include the necessary scopes
|
617 |
+
|
618 |
+
**Required Permissions:**
|
619 |
+
- `read-repos` - Read access to repositories
|
620 |
+
- `write-repos` - Write access to create repositories
|
621 |
+
- `manage-repos` - Manage repository settings
|
622 |
|
623 |
**Steps to fix:**
|
624 |
+
1. **Logout**: Click the logout button in the sidebar
|
625 |
+
2. **Login Again**: Click "Sign in with Hugging Face" again
|
626 |
+
3. **Grant All Permissions**: When the authorization page appears, make sure to check ALL the requested permissions:
|
627 |
+
- β
read-repos
|
628 |
+
- β
write-repos
|
629 |
+
- β
manage-repos
|
630 |
+
4. **Complete Authorization**: Click "Authorize" to complete the login
|
631 |
+
5. **Try Deploying**: Try deploying again
|
632 |
+
|
633 |
+
**Important:** Make sure you see all three permissions checked on the authorization page before clicking "Authorize".
|
634 |
+
|
635 |
+
---
|
636 |
+
*Please log in again with full permissions.*""", update_oauth_status(oauth_profile, oauth_token)
|
637 |
+
else:
|
638 |
+
return f"""β **Repository Access Error**
|
639 |
+
|
640 |
+
Error: {str(repo_error)}
|
641 |
+
|
642 |
+
This could be due to:
|
643 |
+
- Network connectivity issues
|
644 |
+
- Hugging Face API temporary problems
|
645 |
+
- Account-specific restrictions
|
646 |
+
|
647 |
+
**Steps to fix:**
|
648 |
+
1. Check your internet connection
|
649 |
+
2. Try logging out and logging back in
|
650 |
+
3. Wait a few minutes and try again
|
651 |
+
4. If the problem persists, check your Hugging Face account settings
|
652 |
|
653 |
---
|
654 |
+
*Please try again or contact support if the issue persists.*""", update_oauth_status(oauth_profile, oauth_token)
|
655 |
|
656 |
except Exception as token_error:
|
657 |
print(f"Debug: Token test failed: {token_error}")
|
|
|
670 |
4. Try deploying again
|
671 |
|
672 |
---
|
673 |
+
*Please log in again.*""", update_oauth_status(oauth_profile, oauth_token)
|
674 |
|
675 |
# Extract prompts from history
|
676 |
prompts = []
|
|
|
678 |
if isinstance(user_msg, str) and user_msg.strip():
|
679 |
prompts.append(user_msg.strip())
|
680 |
|
681 |
+
# Test if user can create repositories by attempting a test creation
|
682 |
+
try:
|
683 |
+
test_api = HfApi(token=user_token)
|
684 |
+
|
685 |
+
# Try to create a test repository to verify permissions
|
686 |
+
test_repo_name = f"{username}/test-permissions-{int(time.time())}"
|
687 |
+
print(f"Debug: Testing repository creation with: {test_repo_name}")
|
688 |
+
|
689 |
+
try:
|
690 |
+
# Attempt to create a test repository
|
691 |
+
test_repo_url = test_api.create_repo(
|
692 |
+
repo_id=test_repo_name,
|
693 |
+
repo_type="model",
|
694 |
+
private=True,
|
695 |
+
exist_ok=False,
|
696 |
+
token=user_token
|
697 |
+
)
|
698 |
+
print(f"Debug: Successfully created test repository: {test_repo_url}")
|
699 |
+
|
700 |
+
# Clean up the test repository
|
701 |
+
try:
|
702 |
+
test_api.delete_repo(repo_id=test_repo_name, token=user_token)
|
703 |
+
print(f"Debug: Successfully cleaned up test repository")
|
704 |
+
except Exception as cleanup_error:
|
705 |
+
print(f"Debug: Could not clean up test repository: {cleanup_error}")
|
706 |
+
|
707 |
+
except Exception as test_create_error:
|
708 |
+
print(f"Debug: Could not create test repository: {test_create_error}")
|
709 |
+
error_msg = str(test_create_error).lower()
|
710 |
+
|
711 |
+
if "403" in error_msg or "forbidden" in error_msg:
|
712 |
+
return """β **Repository Creation Permission Denied**
|
713 |
+
|
714 |
+
Your Hugging Face account doesn't have permission to create repositories. This could be because:
|
715 |
+
|
716 |
+
1. **Account Type**: Your account type may not allow repository creation
|
717 |
+
2. **Organization Restrictions**: If you're part of an organization, there may be restrictions
|
718 |
+
3. **Account Status**: Your account may be limited or suspended
|
719 |
+
|
720 |
+
**Steps to fix:**
|
721 |
+
1. **Check Account Status**: Visit https://huggingface.co/settings/account to check your account status
|
722 |
+
2. **Verify Account Type**: Make sure your account allows repository creation
|
723 |
+
3. **Contact Support**: If you believe this is an error, contact Hugging Face support
|
724 |
+
4. **Try Different Account**: Consider using a different Hugging Face account
|
725 |
+
|
726 |
+
**Note:** Free accounts should be able to create repositories. If you're having issues, it might be a temporary restriction.
|
727 |
+
|
728 |
+
---
|
729 |
+
*Please check your account settings or try with a different account.*""", update_oauth_status(oauth_profile, oauth_token)
|
730 |
+
else:
|
731 |
+
return f"""β **Repository Creation Test Failed**
|
732 |
+
|
733 |
+
Error: {str(test_create_error)}
|
734 |
+
|
735 |
+
This could be due to:
|
736 |
+
- Network connectivity issues
|
737 |
+
- Hugging Face API temporary problems
|
738 |
+
- Account-specific restrictions
|
739 |
+
|
740 |
+
**Steps to fix:**
|
741 |
+
1. Check your internet connection
|
742 |
+
2. Wait a few minutes and try again
|
743 |
+
3. If the problem persists, check your Hugging Face account settings
|
744 |
+
|
745 |
+
---
|
746 |
+
*Please try again or contact support if the issue persists.*""", update_oauth_status(oauth_profile, oauth_token)
|
747 |
+
|
748 |
+
except Exception as test_error:
|
749 |
+
print(f"Debug: Repository creation test failed: {test_error}")
|
750 |
+
return f"""β **Permission Test Failed**
|
751 |
+
|
752 |
+
Could not test repository creation permissions: {str(test_error)}
|
753 |
+
|
754 |
+
**Steps to fix:**
|
755 |
+
1. Check your internet connection
|
756 |
+
2. Try logging out and logging back in
|
757 |
+
3. Wait a few minutes and try again
|
758 |
+
|
759 |
+
---
|
760 |
+
*Please try again or contact support if the issue persists.*""", update_oauth_status(oauth_profile, oauth_token)
|
761 |
+
|
762 |
# Use user's OAuth token to create space under their account
|
763 |
result = create_space_from_html(title.strip(), html_content, prompts, user_token, username)
|
764 |
|
|
|
776 |
- Manage your space from your Hugging Face dashboard
|
777 |
|
778 |
---
|
779 |
+
*Generated with β€οΈ using AnyCoder*""", update_oauth_status(oauth_profile, oauth_token)
|
780 |
else:
|
781 |
return f"""β **Deployment failed**
|
782 |
|
|
|
789 |
- Make sure your Hugging Face account has the necessary permissions
|
790 |
|
791 |
---
|
792 |
+
*Please try again or contact support if the issue persists.*""", update_oauth_status(oauth_profile, oauth_token)
|
793 |
|
794 |
def history_to_messages(history: History, system: str) -> Messages:
|
795 |
messages = [{'role': 'system', 'content': system}]
|
|
|
863 |
def clear_history():
|
864 |
return [], [], None, "" # Empty lists for both tuple format and chatbot messages, None for file, empty string for website URL
|
865 |
|
866 |
+
def update_oauth_status(oauth_profile: gr.OAuthProfile = None, oauth_token: gr.OAuthToken = None):
|
867 |
+
"""Update the OAuth status indicator based on login state"""
|
868 |
+
if not oauth_profile or not oauth_token:
|
869 |
+
return "π **Login Required**\nSign in to deploy applications"
|
870 |
+
|
871 |
+
# Check if we have the required scopes
|
872 |
+
scopes_valid, missing_scopes = validate_oauth_scopes(oauth_token)
|
873 |
+
|
874 |
+
if scopes_valid:
|
875 |
+
return f"β
**Logged in as {oauth_profile.name}**\nReady to deploy applications"
|
876 |
+
else:
|
877 |
+
missing_list = ", ".join(missing_scopes)
|
878 |
+
return f"β οΈ **Incomplete Permissions**\nMissing: {missing_list}\nPlease logout and login again"
|
879 |
+
|
880 |
def update_image_input_visibility(model):
|
881 |
"""Update image input visibility based on selected model"""
|
882 |
is_ernie_vl = model.get("id") == "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT"
|
|
|
1544 |
# OAuth components are automatically injected as function parameters
|
1545 |
# when using gr.LoginButton() - no need to create them separately
|
1546 |
|
1547 |
+
# OAuth status will be updated automatically by Gradio's OAuth system
|
1548 |
+
|
1549 |
# Main input section
|
1550 |
input = gr.Textbox(
|
1551 |
label="What would you like to build?",
|
|
|
1636 |
else:
|
1637 |
gr.Markdown("β
Web search available")
|
1638 |
|
1639 |
+
# OAuth status indicator
|
1640 |
+
oauth_status = gr.Markdown(
|
1641 |
+
value="π **Login Required**\nSign in to deploy applications",
|
1642 |
+
visible=True
|
1643 |
+
)
|
1644 |
+
|
1645 |
# Hidden elements for functionality
|
1646 |
model_display = gr.Markdown(f"**Model:** {AVAILABLE_MODELS[0]['name']}", visible=False)
|
1647 |
|
|
|
1688 |
### Prerequisites
|
1689 |
1. **Login Required**: You must be logged in with your Hugging Face account
|
1690 |
2. **Permissions**: Grant the following permissions when logging in:
|
1691 |
+
- β
**read-repos** - Read access to repositories
|
1692 |
+
- β
**write-repos** - Write access to create repositories
|
1693 |
+
- β
**manage-repos** - Manage repository settings
|
1694 |
|
1695 |
### Steps to Deploy
|
1696 |
1. **Login**: Click "Sign in with Hugging Face" in the sidebar
|
1697 |
+
2. **Authorize Permissions**: When the authorization page appears, make sure to grant ALL the requested permissions
|
1698 |
+
3. **Generate Code**: Generate some HTML code using the AI
|
1699 |
+
4. **Enter Title**: In the sidebar, enter a title for your space (e.g., "My Todo App")
|
1700 |
+
5. **Deploy**: Click the "π Deploy to Space" button
|
1701 |
|
1702 |
### What Happens
|
1703 |
- Your application will be deployed to Hugging Face Spaces under your account
|
|
|
1711 |
- Try logging out and logging back in
|
1712 |
- Check that your Hugging Face account can create repositories
|
1713 |
|
1714 |
+
**Important**: You must grant ALL three permissions during the OAuth authorization process.
|
1715 |
+
|
1716 |
---
|
1717 |
*Your application will be deployed to Hugging Face Spaces and you'll get a shareable URL!*""",
|
1718 |
label="Deployment Status"
|
|
|
1733 |
deploy_btn.click(
|
1734 |
deploy_to_space,
|
1735 |
inputs=[space_title_input, code_output, history],
|
1736 |
+
outputs=[deploy_output, oauth_status],
|
1737 |
api_name="deploy"
|
1738 |
)
|
1739 |
|