Spaces:
Running
Running
update
Browse files
README.md
CHANGED
@@ -11,6 +11,7 @@ disable_embedding: true
|
|
11 |
hf_oauth: true
|
12 |
hf_oauth_scopes:
|
13 |
- write-repos
|
|
|
14 |
---
|
15 |
|
16 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
11 |
hf_oauth: true
|
12 |
hf_oauth_scopes:
|
13 |
- write-repos
|
14 |
+
- manage-repos
|
15 |
---
|
16 |
|
17 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -204,18 +204,20 @@ def create_space_from_html(title: str, html_content: str, prompts: List[str] = N
|
|
204 |
# Create API client with user token
|
205 |
user_hf_api = HfApi(token=api_token)
|
206 |
|
207 |
-
#
|
208 |
-
|
209 |
-
|
210 |
-
|
|
|
211 |
username = user_info.get('name', 'user')
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
219 |
|
220 |
# Clean the title for use as repo name
|
221 |
clean_title = re.sub(r'[^a-zA-Z0-9_-]', '-', title.lower())
|
@@ -225,14 +227,22 @@ def create_space_from_html(title: str, html_content: str, prompts: List[str] = N
|
|
225 |
timestamp = int(time.time())
|
226 |
repo_name = f"{username}/{clean_title}-{timestamp}"
|
227 |
|
|
|
|
|
|
|
228 |
# Create the space
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
# Prepare the HTML content with proper structure
|
238 |
html_template = """<!DOCTYPE html>
|
@@ -387,6 +397,12 @@ To deploy your application, you need to be logged in with your Hugging Face acco
|
|
387 |
username = oauth_profile.name
|
388 |
user_token = oauth_token.token
|
389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
# Extract prompts from history
|
391 |
prompts = []
|
392 |
for user_msg, _ in history:
|
|
|
204 |
# Create API client with user token
|
205 |
user_hf_api = HfApi(token=api_token)
|
206 |
|
207 |
+
# Debug: Test the token by getting user info
|
208 |
+
try:
|
209 |
+
user_info = user_hf_api.whoami()
|
210 |
+
print(f"Debug: User info from API: {user_info}")
|
211 |
+
if not username:
|
212 |
username = user_info.get('name', 'user')
|
213 |
+
print(f"Debug: Final username: {username}")
|
214 |
+
except Exception as e:
|
215 |
+
print(f"Debug: Could not get user info: {e}")
|
216 |
+
return {
|
217 |
+
"success": False,
|
218 |
+
"error": f"Invalid or expired token: {str(e)}",
|
219 |
+
"message": "Please check your Hugging Face token and try logging in again"
|
220 |
+
}
|
221 |
|
222 |
# Clean the title for use as repo name
|
223 |
clean_title = re.sub(r'[^a-zA-Z0-9_-]', '-', title.lower())
|
|
|
227 |
timestamp = int(time.time())
|
228 |
repo_name = f"{username}/{clean_title}-{timestamp}"
|
229 |
|
230 |
+
print(f"Debug: Attempting to create space: {repo_name}")
|
231 |
+
print(f"Debug: Using token for user: {username}")
|
232 |
+
|
233 |
# Create the space
|
234 |
+
try:
|
235 |
+
repo_url = user_hf_api.create_repo(
|
236 |
+
repo_id=repo_name,
|
237 |
+
repo_type="space",
|
238 |
+
space_sdk="static",
|
239 |
+
private=False,
|
240 |
+
exist_ok=False
|
241 |
+
)
|
242 |
+
print(f"Debug: Successfully created space: {repo_url}")
|
243 |
+
except Exception as e:
|
244 |
+
print(f"Debug: Failed to create space: {e}")
|
245 |
+
raise e
|
246 |
|
247 |
# Prepare the HTML content with proper structure
|
248 |
html_template = """<!DOCTYPE html>
|
|
|
397 |
username = oauth_profile.name
|
398 |
user_token = oauth_token.token
|
399 |
|
400 |
+
# Debug: Print token info (without exposing the actual token)
|
401 |
+
print(f"Debug: Username from OAuth: {username}")
|
402 |
+
print(f"Debug: Token type: {type(user_token)}")
|
403 |
+
print(f"Debug: Token length: {len(user_token) if user_token else 0}")
|
404 |
+
print(f"Debug: Token starts with: {user_token[:10] if user_token else 'None'}...")
|
405 |
+
|
406 |
# Extract prompts from history
|
407 |
prompts = []
|
408 |
for user_msg, _ in history:
|