update
Browse files10 unmodified lines11121314151610 unmodified lineshf_oauth: truehf_oauth_scopes:- write-repos---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference10 unmodified lines1112131415161710 unmodified lineshf_oauth: truehf_oauth_scopes:- write-repos- manage-repos---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
203 unmodified lines2042052062072082092102112122132142152162172182192202213 unmodified lines225226227228229230231232233234235236237238148 unmodified lines387388389390391392203 unmodified lines# Create API client with user tokenuser_hf_api = HfApi(token=api_token)# Get the current user's username if not providedif not username:try:user_info = user_hf_api.whoami()username = user_info.get('name', 'user')except Exception as e:print(f"Could not get user info: {e}")return {"success": False,"error": "Invalid or expired token","message": "Please check your Hugging Face token"}# Clean the title for use as repo nameclean_title = re.sub(r'[^a-zA-Z0-9_-]', '-', title.lower())3 unmodified linestimestamp = int(time.time())repo_name = f"{username}/{clean_title}-{timestamp}"# Create the spacerepo_url = user_hf_api.create_repo(repo_id=repo_name,repo_type="space",space_sdk="static",private=False,exist_ok=False)# Prepare the HTML content with proper structurehtml_template = """<!DOCTYPE html>148 unmodified linesusername = oauth_profile.nameuser_token = oauth_token.token# Extract prompts from historyprompts = []for user_msg, _ in history:203 unmodified lines2042052062072082092102112122132142152162172182192202212222233 unmodified lines227228229230231232233234235236237238239240241242243244245246247248148 unmodified lines397398399400401402403404405406407408203 unmodified lines# Create API client with user tokenuser_hf_api = HfApi(token=api_token)# Debug: Test the token by getting user infotry:user_info = user_hf_api.whoami()print(f"Debug: User info from API: {user_info}")if not username:username = user_info.get('name', 'user')print(f"Debug: Final username: {username}")except Exception as e:print(f"Debug: Could not get user info: {e}")return {"success": False,"error": f"Invalid or expired token: {str(e)}","message": "Please check your Hugging Face token and try logging in again"}# Clean the title for use as repo nameclean_title = re.sub(r'[^a-zA-Z0-9_-]', '-', title.lower())3 unmodified linestimestamp = int(time.time())repo_name = f"{username}/{clean_title}-{timestamp}"print(f"Debug: Attempting to create space: {repo_name}")print(f"Debug: Using token for user: {username}")# Create the spacetry:repo_url = user_hf_api.create_repo(repo_id=repo_name,repo_type="space",space_sdk="static",private=False,exist_ok=False)print(f"Debug: Successfully created space: {repo_url}")except Exception as e:print(f"Debug: Failed to create space: {e}")raise e# Prepare the HTML content with proper structurehtml_template = """<!DOCTYPE html>148 unmodified linesusername = oauth_profile.nameuser_token = oauth_token.token# Debug: Print token info (without exposing the actual token)print(f"Debug: Username from OAuth: {username}")print(f"Debug: Token type: {type(user_token)}")print(f"Debug: Token length: {len(user_token) if user_token else 0}")print(f"Debug: Token starts with: {user_token[:10] if user_token else 'None'}...")# Extract prompts from historyprompts = []for user_msg, _ in history:
README.md+1
app.py+34-18