akhaliq HF Staff commited on
Commit
cf34c7e
·
1 Parent(s): 32ee128

update svelte

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -2076,8 +2076,8 @@ with gr.Blocks(
2076
 
2077
  # Create API client with user's token for proper authentication
2078
  api = HfApi(token=token.token)
2079
- # Only create the repo for new spaces (not updates) and non-Transformers.js and non-Streamlit SDKs
2080
- if not is_update and sdk != "docker" and sdk_name != "Transformers.js":
2081
  try:
2082
  api.create_repo(
2083
  repo_id=repo_id, # e.g. username/space_name
@@ -2143,8 +2143,6 @@ with gr.Blocks(
2143
  exist_ok=True
2144
  )
2145
  print("Duplicated repo result:", duplicated_repo, type(duplicated_repo))
2146
- # Show the duplicated space URL immediately for user feedback
2147
- gr.update(value=f"✅ Space duplicated! [Open your new Space here]({str(duplicated_repo)})", visible=True)
2148
  # Parse the transformers.js output to get the three files
2149
  files = parse_transformers_js_output(code)
2150
 
@@ -2224,7 +2222,11 @@ with gr.Blocks(
2224
  os.unlink(temp_path)
2225
 
2226
  except Exception as e:
2227
- return gr.update(value=f"Error duplicating Transformers.js space: {e}. If this is a RepoUrl object error, ensure you are not accessing a .url attribute and use str(duplicated_repo) for the URL.", visible=True)
 
 
 
 
2228
  # Svelte logic
2229
  elif sdk_name == "Svelte" and not is_update:
2230
  try:
@@ -2239,17 +2241,22 @@ with gr.Blocks(
2239
  exist_ok=True
2240
  )
2241
  print("Duplicated Svelte repo result:", duplicated_repo, type(duplicated_repo))
 
2242
  # Extract the actual repo ID from the duplicated space
2243
  # The duplicated_repo is a RepoUrl object, convert to string and extract the repo ID
2244
- duplicated_repo_str = str(duplicated_repo)
2245
- # Extract username and repo name from the URL
2246
- if "/spaces/" in duplicated_repo_str:
2247
- parts = duplicated_repo_str.split("/spaces/")[-1].split("/")
2248
- if len(parts) >= 2:
2249
- actual_repo_id = f"{parts[0]}/{parts[1]}"
 
 
 
2250
  else:
2251
  actual_repo_id = repo_id # Fallback to original
2252
- else:
 
2253
  actual_repo_id = repo_id # Fallback to original
2254
  print("Actual repo ID for Svelte uploads:", actual_repo_id)
2255
 
@@ -2336,7 +2343,11 @@ with gr.Blocks(
2336
  return gr.update(value=f"✅ {action_text}! [Open your Svelte Space here]({space_url})", visible=True)
2337
 
2338
  except Exception as e:
2339
- return gr.update(value=f"Error duplicating Svelte space: {e}. If this is a RepoUrl object error, ensure you are not accessing a .url attribute and use str(duplicated_repo) for the URL.", visible=True)
 
 
 
 
2340
  # Other SDKs (existing logic)
2341
  if sdk == "static":
2342
  import time
 
2076
 
2077
  # Create API client with user's token for proper authentication
2078
  api = HfApi(token=token.token)
2079
+ # Only create the repo for new spaces (not updates) and non-Transformers.js, non-Streamlit, and non-Svelte SDKs
2080
+ if not is_update and sdk != "docker" and sdk_name not in ["Transformers.js", "Svelte"]:
2081
  try:
2082
  api.create_repo(
2083
  repo_id=repo_id, # e.g. username/space_name
 
2143
  exist_ok=True
2144
  )
2145
  print("Duplicated repo result:", duplicated_repo, type(duplicated_repo))
 
 
2146
  # Parse the transformers.js output to get the three files
2147
  files = parse_transformers_js_output(code)
2148
 
 
2222
  os.unlink(temp_path)
2223
 
2224
  except Exception as e:
2225
+ # Handle potential RepoUrl object errors
2226
+ error_msg = str(e)
2227
+ if "'url'" in error_msg or "RepoUrl" in error_msg:
2228
+ return gr.update(value=f"Error duplicating Transformers.js space: RepoUrl handling error. Please try again. Details: {error_msg}", visible=True)
2229
+ return gr.update(value=f"Error duplicating Transformers.js space: {error_msg}", visible=True)
2230
  # Svelte logic
2231
  elif sdk_name == "Svelte" and not is_update:
2232
  try:
 
2241
  exist_ok=True
2242
  )
2243
  print("Duplicated Svelte repo result:", duplicated_repo, type(duplicated_repo))
2244
+
2245
  # Extract the actual repo ID from the duplicated space
2246
  # The duplicated_repo is a RepoUrl object, convert to string and extract the repo ID
2247
+ try:
2248
+ duplicated_repo_str = str(duplicated_repo)
2249
+ # Extract username and repo name from the URL
2250
+ if "/spaces/" in duplicated_repo_str:
2251
+ parts = duplicated_repo_str.split("/spaces/")[-1].split("/")
2252
+ if len(parts) >= 2:
2253
+ actual_repo_id = f"{parts[0]}/{parts[1]}"
2254
+ else:
2255
+ actual_repo_id = repo_id # Fallback to original
2256
  else:
2257
  actual_repo_id = repo_id # Fallback to original
2258
+ except Exception as e:
2259
+ print(f"Error extracting repo ID from duplicated_repo: {e}")
2260
  actual_repo_id = repo_id # Fallback to original
2261
  print("Actual repo ID for Svelte uploads:", actual_repo_id)
2262
 
 
2343
  return gr.update(value=f"✅ {action_text}! [Open your Svelte Space here]({space_url})", visible=True)
2344
 
2345
  except Exception as e:
2346
+ # Handle potential RepoUrl object errors
2347
+ error_msg = str(e)
2348
+ if "'url'" in error_msg or "RepoUrl" in error_msg:
2349
+ return gr.update(value=f"Error duplicating Svelte space: RepoUrl handling error. Please try again. Details: {error_msg}", visible=True)
2350
+ return gr.update(value=f"Error duplicating Svelte space: {error_msg}", visible=True)
2351
  # Other SDKs (existing logic)
2352
  if sdk == "static":
2353
  import time