Spaces:
Running
Running
update
Browse files
app.py
CHANGED
@@ -2856,6 +2856,27 @@ with gr.Blocks(
|
|
2856 |
return gr.update(value="π Update Space")
|
2857 |
else:
|
2858 |
return gr.update(value="π Deploy App")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2859 |
|
2860 |
# Load project button event
|
2861 |
load_project_btn.click(
|
@@ -2872,6 +2893,10 @@ with gr.Blocks(
|
|
2872 |
show_deploy_components,
|
2873 |
None,
|
2874 |
[space_name_input, sdk_dropdown, deploy_btn]
|
|
|
|
|
|
|
|
|
2875 |
)
|
2876 |
# Update preview when code or language changes
|
2877 |
code_output.change(preview_logic, inputs=[code_output, language_dropdown], outputs=sandbox)
|
@@ -3128,18 +3153,27 @@ with gr.Blocks(
|
|
3128 |
except Exception as e:
|
3129 |
# Handle potential RepoUrl object errors
|
3130 |
error_msg = str(e)
|
3131 |
-
if "'url'" in error_msg or "RepoUrl" in error_msg
|
3132 |
-
#
|
3133 |
try:
|
3134 |
-
if
|
3135 |
-
|
3136 |
-
|
3137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3138 |
else:
|
3139 |
-
|
3140 |
-
|
3141 |
except:
|
3142 |
-
|
|
|
|
|
3143 |
|
3144 |
# General error handling for both creation and updates
|
3145 |
action_verb = "updating" if is_update else "duplicating"
|
|
|
2856 |
return gr.update(value="π Update Space")
|
2857 |
else:
|
2858 |
return gr.update(value="π Deploy App")
|
2859 |
+
|
2860 |
+
def preserve_space_info_for_followup(history):
|
2861 |
+
"""Check if this is a followup on an imported project and preserve space info"""
|
2862 |
+
if not history or len(history) == 0:
|
2863 |
+
return [gr.update(), gr.update()]
|
2864 |
+
|
2865 |
+
# Look for imported project pattern in history
|
2866 |
+
for user_msg, assistant_msg in history:
|
2867 |
+
if assistant_msg and 'IMPORTED PROJECT FROM HUGGING FACE SPACE' in assistant_msg:
|
2868 |
+
# Extract space name from the imported project info
|
2869 |
+
import re
|
2870 |
+
space_match = re.search(r'Space:\s*([^\s\n]+)', assistant_msg)
|
2871 |
+
if space_match:
|
2872 |
+
space_name = space_match.group(1)
|
2873 |
+
return [
|
2874 |
+
gr.update(value=space_name, visible=True), # Update space name
|
2875 |
+
gr.update(value="π Update Space", visible=True) # Update button text
|
2876 |
+
]
|
2877 |
+
|
2878 |
+
# No imported project found, return no changes
|
2879 |
+
return [gr.update(), gr.update()]
|
2880 |
|
2881 |
# Load project button event
|
2882 |
load_project_btn.click(
|
|
|
2893 |
show_deploy_components,
|
2894 |
None,
|
2895 |
[space_name_input, sdk_dropdown, deploy_btn]
|
2896 |
+
).then(
|
2897 |
+
preserve_space_info_for_followup,
|
2898 |
+
inputs=[history],
|
2899 |
+
outputs=[space_name_input, deploy_btn]
|
2900 |
)
|
2901 |
# Update preview when code or language changes
|
2902 |
code_output.change(preview_logic, inputs=[code_output, language_dropdown], outputs=sandbox)
|
|
|
3153 |
except Exception as e:
|
3154 |
# Handle potential RepoUrl object errors
|
3155 |
error_msg = str(e)
|
3156 |
+
if "'url'" in error_msg or "RepoUrl" in error_msg:
|
3157 |
+
# For RepoUrl object issues, check if the space was actually created successfully
|
3158 |
try:
|
3159 |
+
# Check if space exists by trying to access it
|
3160 |
+
space_url = f"https://huggingface.co/spaces/{repo_id}"
|
3161 |
+
test_api = HfApi(token=token.token)
|
3162 |
+
space_exists = test_api.space_info(repo_id)
|
3163 |
+
|
3164 |
+
if space_exists and not is_update:
|
3165 |
+
# Space was created successfully despite the RepoUrl error
|
3166 |
+
return gr.update(value=f"β
Deployed! Space was created successfully despite a technical error. [Open your Transformers.js Space here]({space_url})", visible=True)
|
3167 |
+
elif space_exists and is_update:
|
3168 |
+
# Space was updated successfully despite the RepoUrl error
|
3169 |
+
return gr.update(value=f"β
Updated! Space was updated successfully despite a technical error. [Open your Transformers.js Space here]({space_url})", visible=True)
|
3170 |
else:
|
3171 |
+
# Space doesn't exist, real error
|
3172 |
+
return gr.update(value=f"Error: Could not create/update space. Please try again manually at https://huggingface.co/new-space", visible=True)
|
3173 |
except:
|
3174 |
+
# Fallback to informative error with link
|
3175 |
+
repo_url = f"https://huggingface.co/spaces/{repo_id}"
|
3176 |
+
return gr.update(value=f"Error: Could not properly handle space creation response. Space may have been created successfully. Check: {repo_url}", visible=True)
|
3177 |
|
3178 |
# General error handling for both creation and updates
|
3179 |
action_verb = "updating" if is_update else "duplicating"
|