akhaliq HF Staff commited on
Commit
fe566fd
·
1 Parent(s): c66426d
Files changed (2) hide show
  1. backend_api.py +7 -2
  2. frontend/src/app/page.tsx +26 -2
backend_api.py CHANGED
@@ -567,6 +567,7 @@ async def deploy(
567
  raise HTTPException(status_code=401, detail="No HuggingFace token available. Please sign in first.")
568
 
569
  print(f"[Deploy] Attempting deployment with token (first 10 chars): {user_token[:10]}...")
 
570
 
571
  # Check for existing deployed space in this session
572
  existing_repo_id = request.existing_repo_id
@@ -585,6 +586,7 @@ async def deploy(
585
  break
586
 
587
  # Use the standalone deployment function
 
588
  success, message, space_url = deploy_to_huggingface_space(
589
  code=request.code,
590
  language=request.language,
@@ -598,9 +600,12 @@ async def deploy(
598
  )
599
 
600
  if success:
 
 
 
 
601
  # Track deployed space in session for follow-up updates
602
  if session_token and session_token in user_sessions:
603
- repo_id = space_url.split("/spaces/")[-1] if space_url else None
604
  if repo_id:
605
  session = user_sessions[session_token]
606
  deployed_spaces = session.get("deployed_spaces", [])
@@ -623,7 +628,7 @@ async def deploy(
623
  "success": True,
624
  "space_url": space_url,
625
  "message": message,
626
- "repo_id": repo_id if 'repo_id' in locals() else None
627
  }
628
  else:
629
  # Provide user-friendly error message based on the error
 
567
  raise HTTPException(status_code=401, detail="No HuggingFace token available. Please sign in first.")
568
 
569
  print(f"[Deploy] Attempting deployment with token (first 10 chars): {user_token[:10]}...")
570
+ print(f"[Deploy] Request parameters - language: {request.language}, space_name: {request.space_name}, existing_repo_id: {request.existing_repo_id}")
571
 
572
  # Check for existing deployed space in this session
573
  existing_repo_id = request.existing_repo_id
 
586
  break
587
 
588
  # Use the standalone deployment function
589
+ print(f"[Deploy] Calling deploy_to_huggingface_space with existing_repo_id: {existing_repo_id}")
590
  success, message, space_url = deploy_to_huggingface_space(
591
  code=request.code,
592
  language=request.language,
 
600
  )
601
 
602
  if success:
603
+ # Extract repo_id from space_url
604
+ repo_id = space_url.split("/spaces/")[-1] if space_url else None
605
+ print(f"[Deploy] Success! Repo ID: {repo_id}")
606
+
607
  # Track deployed space in session for follow-up updates
608
  if session_token and session_token in user_sessions:
 
609
  if repo_id:
610
  session = user_sessions[session_token]
611
  deployed_spaces = session.get("deployed_spaces", [])
 
628
  "success": True,
629
  "space_url": space_url,
630
  "message": message,
631
+ "repo_id": repo_id
632
  }
633
  else:
634
  # Provide user-friendly error message based on the error
frontend/src/app/page.tsx CHANGED
@@ -193,6 +193,15 @@ export default function Home() {
193
  }
194
 
195
  try {
 
 
 
 
 
 
 
 
 
196
  const response = await apiClient.deploy({
197
  code: generatedCode,
198
  space_name: spaceName,
@@ -204,7 +213,15 @@ export default function Home() {
204
  if (response.success) {
205
  // Update current repo ID if we got one back
206
  if (response.repo_id) {
 
207
  setCurrentRepoId(response.repo_id);
 
 
 
 
 
 
 
208
  }
209
 
210
  // Add deployment message to chat
@@ -244,24 +261,31 @@ export default function Home() {
244
  };
245
 
246
  const handleImport = (code: string, language: Language, importUrl?: string) => {
 
247
  setGeneratedCode(code);
248
  setSelectedLanguage(language);
249
 
250
  // Extract repo_id from import URL if provided
251
  if (importUrl) {
252
  const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);
 
253
  if (spaceMatch) {
254
  const importedRepoId = spaceMatch[1];
 
255
  // Only set as current repo if user owns it
256
  if (username && importedRepoId.startsWith(`${username}/`)) {
257
  setCurrentRepoId(importedRepoId);
258
- console.log('[Import] Set current repo to:', importedRepoId);
259
  } else {
260
  // User doesn't own the imported space, clear current repo
261
  setCurrentRepoId(null);
262
- console.log('[Import] User does not own imported space:', importedRepoId);
263
  }
 
 
264
  }
 
 
265
  }
266
 
267
  // Add messages that include the imported code so LLM can see it
 
193
  }
194
 
195
  try {
196
+ console.log('[Deploy] Deploying with params:', {
197
+ language: selectedLanguage,
198
+ space_name: spaceName,
199
+ existing_repo_id: existingRepoId,
200
+ currentRepoId: currentRepoId,
201
+ username: username,
202
+ code_length: generatedCode.length
203
+ });
204
+
205
  const response = await apiClient.deploy({
206
  code: generatedCode,
207
  space_name: spaceName,
 
213
  if (response.success) {
214
  // Update current repo ID if we got one back
215
  if (response.repo_id) {
216
+ console.log('[Deploy] Setting currentRepoId to:', response.repo_id);
217
  setCurrentRepoId(response.repo_id);
218
+ } else if (response.space_url) {
219
+ // Extract repo_id from space_url as fallback
220
+ const match = response.space_url.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);
221
+ if (match) {
222
+ console.log('[Deploy] Extracted repo_id from URL:', match[1]);
223
+ setCurrentRepoId(match[1]);
224
+ }
225
  }
226
 
227
  // Add deployment message to chat
 
261
  };
262
 
263
  const handleImport = (code: string, language: Language, importUrl?: string) => {
264
+ console.log('[Import] Importing project:', { language, importUrl, username });
265
  setGeneratedCode(code);
266
  setSelectedLanguage(language);
267
 
268
  // Extract repo_id from import URL if provided
269
  if (importUrl) {
270
  const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);
271
+ console.log('[Import] Regex match result:', spaceMatch);
272
  if (spaceMatch) {
273
  const importedRepoId = spaceMatch[1];
274
+ console.log('[Import] Extracted repo_id:', importedRepoId, 'Username:', username);
275
  // Only set as current repo if user owns it
276
  if (username && importedRepoId.startsWith(`${username}/`)) {
277
  setCurrentRepoId(importedRepoId);
278
+ console.log('[Import] Set current repo to:', importedRepoId);
279
  } else {
280
  // User doesn't own the imported space, clear current repo
281
  setCurrentRepoId(null);
282
+ console.log('[Import] ⚠️ User does not own imported space:', importedRepoId, '(username:', username, ')');
283
  }
284
+ } else {
285
+ console.log('[Import] ⚠️ Could not extract repo_id from URL:', importUrl);
286
  }
287
+ } else {
288
+ console.log('[Import] No import URL provided');
289
  }
290
 
291
  // Add messages that include the imported code so LLM can see it