akhaliq HF Staff commited on
Commit
1a400b9
Β·
1 Parent(s): da10426

fix loaded space

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -8063,11 +8063,6 @@ with gr.Blocks(
8063
  def hide_deploy_components(*args):
8064
  return gr.Button(visible=True)
8065
 
8066
- def preserve_space_info_for_followup(history):
8067
- """Check if this is a followup on an imported project - no longer needed with random names"""
8068
- # Always return standard deploy button since we use random names
8069
- return gr.update(value="πŸš€ Deploy App")
8070
-
8071
  # Unified import event
8072
  load_project_btn.click(
8073
  handle_import_project,
@@ -8271,7 +8266,7 @@ with gr.Blocks(
8271
  username = profile.username if profile else None
8272
  existing_space = None
8273
 
8274
- # Look for previous deployment in history
8275
  if history and username:
8276
  for user_msg, assistant_msg in history:
8277
  if assistant_msg and "βœ… Deployed!" in assistant_msg:
@@ -8288,6 +8283,18 @@ with gr.Blocks(
8288
  if match:
8289
  existing_space = match.group(1)
8290
  break
 
 
 
 
 
 
 
 
 
 
 
 
8291
 
8292
  # Call the original deploy function
8293
  status = deploy_to_user_space_original(code, language, existing_space, profile, token)
@@ -8296,7 +8303,10 @@ with gr.Blocks(
8296
  updated_history = history
8297
  if isinstance(status, dict) and "value" in status and "βœ…" in status["value"]:
8298
  action_type = "Deploy" if "Deployed!" in status["value"] else "Update"
8299
- updated_history = history + [[f"{action_type} {language} app", status["value"]]]
 
 
 
8300
 
8301
  return [status, updated_history]
8302
 
 
8063
  def hide_deploy_components(*args):
8064
  return gr.Button(visible=True)
8065
 
 
 
 
 
 
8066
  # Unified import event
8067
  load_project_btn.click(
8068
  handle_import_project,
 
8266
  username = profile.username if profile else None
8267
  existing_space = None
8268
 
8269
+ # Look for previous deployment or imported space in history
8270
  if history and username:
8271
  for user_msg, assistant_msg in history:
8272
  if assistant_msg and "βœ… Deployed!" in assistant_msg:
 
8283
  if match:
8284
  existing_space = match.group(1)
8285
  break
8286
+ elif user_msg and user_msg.startswith("Imported Space from"):
8287
+ import re
8288
+ # Extract space name from import message
8289
+ match = re.search(r'huggingface\.co/spaces/([^/\s\)]+/[^/\s\)]+)', user_msg)
8290
+ if match:
8291
+ imported_space = match.group(1)
8292
+ # Only use imported space if user owns it (can update it)
8293
+ if imported_space.startswith(f"{username}/"):
8294
+ existing_space = imported_space
8295
+ break
8296
+ # If user doesn't own the imported space, we'll create a new one
8297
+ # (existing_space remains None, triggering new deployment)
8298
 
8299
  # Call the original deploy function
8300
  status = deploy_to_user_space_original(code, language, existing_space, profile, token)
 
8303
  updated_history = history
8304
  if isinstance(status, dict) and "value" in status and "βœ…" in status["value"]:
8305
  action_type = "Deploy" if "Deployed!" in status["value"] else "Update"
8306
+ if existing_space:
8307
+ updated_history = history + [[f"{action_type} {language} app to {existing_space}", status["value"]]]
8308
+ else:
8309
+ updated_history = history + [[f"{action_type} {language} app", status["value"]]]
8310
 
8311
  return [status, updated_history]
8312