Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import json
|
|
4 |
import os
|
5 |
import tempfile
|
6 |
import shlex
|
7 |
-
from huggingface_hub import HfApi
|
8 |
|
9 |
from build_logic import (
|
10 |
_get_api_token as build_logic_get_api_token,
|
@@ -460,7 +460,7 @@ def generate_and_stage_changes(ai_response_content, current_files_state, hf_owne
|
|
460 |
elif change["type"] == "CREATE_PR":
|
461 |
md_summary.append(f"- **🤝 Create Pull Request:** From `{change.get('source_repo_id', '...')}` to `{change.get('target_repo_id', '...')}`")
|
462 |
md_summary.append(f" - Title: `{change.get('title', '...')}`")
|
463 |
-
if change.get('body'): md_summary.append(f" - Body: `{change.get('body', '...')[:100]}{'...' if len(change.get('
|
464 |
elif change["type"] == "ADD_COMMENT":
|
465 |
md_summary.append(f"- **💬 Add Comment:** On `{change.get('repo_id', '...')}`")
|
466 |
md_summary.append(f" - Comment: `{change.get('comment', '...')[:100]}{'...' if len(change.get('comment', '')) > 100 else ''}`")
|
@@ -944,13 +944,13 @@ def handle_confirm_changes(hf_api_key, owner_name, space_name, changeset):
|
|
944 |
|
945 |
file_browser_update = gr.update(visible=True, choices=sorted(refreshed_file_list or []), value=None)
|
946 |
|
|
|
947 |
if owner_name and space_name:
|
948 |
sub_owner = re.sub(r'[^a-z0-9\-]+', '-', owner_name.lower()).strip('-') or 'owner'
|
949 |
sub_repo = re.sub(r'[^a-z0-9\-]+', '-', space_name.lower()).strip('-') or 'space'
|
950 |
iframe_url = f"https://{sub_owner}-{sub_repo}{'.static.hf.space' if sdk == 'static' else '.hf.space'}"
|
951 |
iframe_update = gr.update(value=f'<iframe src="{iframe_url}?__theme=light&embed=true" width="100%" height="500px"></iframe>', visible=True)
|
952 |
-
|
953 |
-
iframe_update = gr.update(value=None, visible=False)
|
954 |
|
955 |
runtime_status_md = handle_refresh_space_status(hf_api_key, owner_name, space_name)
|
956 |
runtime_status_update = gr.update(value=runtime_status_md)
|
@@ -1001,7 +1001,7 @@ def update_models_dropdown(provider_select):
|
|
1001 |
selected_value = default_model if default_model in models else (models[0] if models else None)
|
1002 |
return gr.update(choices=models, value=selected_value)
|
1003 |
|
1004 |
-
def handle_detect_user(hf_api_key_ui,
|
1005 |
# Outputs for detect_user_button.click (3 outputs)
|
1006 |
# [status_output, owner_name_input, list_spaces_display]
|
1007 |
|
@@ -1023,12 +1023,22 @@ def handle_detect_user(hf_api_key_ui, owner_name_ui):
|
|
1023 |
owner_update = gr.update(value=owner_name)
|
1024 |
|
1025 |
# Immediately trigger listing spaces using the detected owner
|
1026 |
-
|
|
|
|
|
1027 |
if list_err:
|
1028 |
list_spaces_update = gr.update(value=f"List Spaces Error: {list_err}")
|
1029 |
_status += f" | List Spaces Error: {list_err}"
|
1030 |
else:
|
1031 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1032 |
|
1033 |
yield gr.update(value=_status), owner_update, list_spaces_update
|
1034 |
|
@@ -1271,13 +1281,17 @@ def handle_build_space_button(hf_api_key_ui, ui_space_name_part, ui_owner_name_p
|
|
1271 |
try:
|
1272 |
api.create_repo(repo_id=repo_id_target, repo_type="space", space_sdk=space_sdk_ui, private=is_private_ui, exist_ok=True)
|
1273 |
build_status_messages.append(f"CREATE_SPACE: Successfully created or ensured space [{repo_id_target}](https://huggingface.co/spaces/{repo_id_target}) exists.")
|
1274 |
-
|
|
|
|
|
|
|
|
|
|
|
1275 |
except Exception as e:
|
1276 |
msg = f"CREATE_SPACE Error: {e}"
|
1277 |
build_status_messages.append(msg)
|
1278 |
errors_occurred = True
|
1279 |
-
_build_status = f"Build Error: {msg}. Cannot proceed with file upload."
|
1280 |
-
yield ( gr.update(value=_build_status), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() ); return
|
1281 |
|
1282 |
_build_status = " | ".join(build_status_messages)
|
1283 |
yield ( gr.update(value=_build_status), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() )
|
@@ -1492,9 +1506,7 @@ def handle_refresh_space_status(hf_api_key_ui, ui_owner_name, ui_space_name):
|
|
1492 |
log_link = status_details.get('full_log_link')
|
1493 |
if log_link and log_link != "#": md_lines.append(f"- [View Full Logs]({log_link})\n")
|
1494 |
# Add build logs link if available (common pattern in Space status)
|
1495 |
-
if
|
1496 |
-
sub_owner = re.sub(r'[^a-z0-9\-]+', '-', ui_owner_name.lower()).strip('-') or 'owner'
|
1497 |
-
sub_repo = re.sub(r'[^a-z0-9\-]+', '-', ui_space_name.lower()).strip('-') or 'space'
|
1498 |
build_logs_url = f"https://huggingface.co/spaces/{ui_owner_name}/{ui_space_name}/build-logs"
|
1499 |
md_lines.append(f"- [View Build Logs]({build_logs_url})\n")
|
1500 |
|
@@ -1506,7 +1518,7 @@ def handle_refresh_space_status(hf_api_key_ui, ui_owner_name, ui_space_name):
|
|
1506 |
elif repo_info:
|
1507 |
md_lines.append(f"- **SDK:** `{repo_info.get('sdk', 'N/A')}`\n")
|
1508 |
md_lines.append(f"- **File Count:** `{repo_info.get('file_count', 'N/A')}`\n")
|
1509 |
-
if
|
1510 |
repo_url = f"https://huggingface.co/spaces/{ui_owner_name}/{ui_space_name}/tree/main"
|
1511 |
md_lines.append(f"- [View Repository Files]({repo_url})\n")
|
1512 |
|
@@ -1628,14 +1640,13 @@ def handle_manual_duplicate_space(hf_api_key_ui, source_owner, source_space_name
|
|
1628 |
|
1629 |
else: # If duplication had errors, don't attempt reload of new space, stay on current
|
1630 |
reload_error = "Reload skipped due to duplication errors."
|
1631 |
-
_formatted, _detected, _download
|
|
|
1632 |
_file_browser_update = gr.update() # Keep current file browser state
|
1633 |
_iframe_html_update = gr.update() # Keep current iframe state
|
1634 |
runtime_status_update = handle_refresh_space_status(hf_api_key_ui, source_owner, source_space_name) # Refresh status of source space
|
1635 |
new_owner = source_owner # Revert fields to source space
|
1636 |
new_space_name = source_space_name
|
1637 |
-
# Need to re-generate _formatted, _detected, _download based on source space if errors occurred
|
1638 |
-
_formatted, _detected, _download = _generate_ui_outputs_from_cache(source_owner, source_space_name)
|
1639 |
|
1640 |
|
1641 |
# Generate final UI based on successful/failed reload
|
@@ -1787,29 +1798,40 @@ with gr.Blocks(theme=custom_theme, css=custom_css) as demo:
|
|
1787 |
|
1788 |
provider_select.change(update_models_dropdown, inputs=provider_select, outputs=model_select)
|
1789 |
|
1790 |
-
chat_inputs = [
|
1791 |
-
|
1792 |
-
|
1793 |
-
|
1794 |
-
|
1795 |
-
|
|
|
|
|
|
|
|
|
1796 |
|
1797 |
send_chat_button.click(handle_chat_submit, inputs=chat_inputs, outputs=chat_outputs)
|
1798 |
chat_message_input.submit(handle_chat_submit, inputs=chat_inputs, outputs=chat_outputs)
|
1799 |
|
1800 |
confirm_inputs = [hf_api_key_input, owner_name_input, space_name_input, changeset_state] # 4 inputs
|
1801 |
-
confirm_outputs = [
|
1802 |
-
|
1803 |
-
|
|
|
|
|
1804 |
confirm_button.click(handle_confirm_changes, inputs=confirm_inputs, outputs=confirm_outputs)
|
1805 |
|
1806 |
-
cancel_outputs = [
|
|
|
|
|
|
|
1807 |
cancel_button.click(handle_cancel_changes, inputs=None, outputs=cancel_outputs)
|
1808 |
|
1809 |
-
load_space_outputs = [
|
1810 |
-
|
1811 |
-
|
1812 |
-
|
|
|
|
|
1813 |
load_space_button.click(
|
1814 |
fn=handle_load_existing_space,
|
1815 |
inputs=[hf_api_key_input, owner_name_input, space_name_input], # 3 inputs
|
@@ -1817,47 +1839,58 @@ with gr.Blocks(theme=custom_theme, css=custom_css) as demo:
|
|
1817 |
)
|
1818 |
|
1819 |
detect_user_outputs = [status_output, owner_name_input, list_spaces_display] # 3 outputs
|
|
|
|
|
1820 |
detect_user_button.click(fn=handle_detect_user, inputs=[hf_api_key_input, owner_name_input], outputs=detect_user_outputs) # 2 inputs
|
1821 |
|
1822 |
-
build_outputs = [
|
1823 |
-
|
1824 |
-
|
1825 |
-
|
1826 |
-
|
|
|
|
|
|
|
|
|
|
|
1827 |
build_space_button.click(fn=handle_build_space_button, inputs=build_inputs, outputs=build_outputs)
|
1828 |
|
1829 |
-
file_edit_load_outputs = [file_content_editor, edit_status_display, commit_message_input] # Corrected: 3 outputs
|
1830 |
file_browser_dropdown.change(
|
1831 |
fn=handle_load_file_for_editing,
|
1832 |
inputs=[hf_api_key_input, space_name_input, owner_name_input, file_browser_dropdown], # 4 inputs
|
1833 |
-
outputs=
|
1834 |
)
|
1835 |
|
1836 |
-
commit_file_outputs = [edit_status_display, file_browser_dropdown, formatted_space_output_display, detected_files_preview, download_button] # 5 outputs
|
1837 |
update_file_button.click(
|
1838 |
fn=handle_commit_file_changes,
|
1839 |
inputs=[hf_api_key_input, space_name_input, owner_name_input, file_browser_dropdown, file_content_editor, commit_message_input], # 6 inputs
|
1840 |
outputs=commit_file_outputs
|
1841 |
)
|
1842 |
|
1843 |
-
delete_file_outputs = [edit_status_display, file_browser_dropdown, file_content_editor, commit_message_input,
|
1844 |
-
formatted_space_output_display, detected_files_preview, download_button] # Corrected: 7 outputs
|
1845 |
delete_file_button.click(
|
1846 |
fn=handle_delete_file,
|
1847 |
inputs=[hf_api_key_input, space_name_input, owner_name_input, file_browser_dropdown], # 4 inputs
|
1848 |
-
outputs=
|
|
|
|
|
|
|
|
|
1849 |
)
|
1850 |
|
1851 |
refresh_status_button.click(fn=handle_refresh_space_status, inputs=[hf_api_key_input, owner_name_input, space_name_input], outputs=[space_runtime_status_display]) # 3 inputs, 1 output
|
1852 |
|
1853 |
-
manual_duplicate_inputs = [hf_api_key_input, owner_name_input, space_name_input, target_owner_input, target_space_name_input, target_private_checkbox] # 6 inputs
|
1854 |
-
manual_duplicate_outputs = [status_output, owner_name_input, space_name_input,
|
1855 |
-
formatted_space_output_display, detected_files_preview, download_button,
|
1856 |
-
file_browser_dropdown, space_iframe_display, space_runtime_status_display] # 9 outputs
|
1857 |
duplicate_space_button.click(fn=handle_manual_duplicate_space, inputs=manual_duplicate_inputs, outputs=manual_duplicate_outputs)
|
1858 |
|
1859 |
list_spaces_button.click(fn=handle_list_spaces, inputs=[hf_api_key_input, owner_name_input], outputs=[list_spaces_display]) # 2 inputs, 1 output
|
1860 |
|
1861 |
|
1862 |
if __name__ == "__main__":
|
1863 |
-
demo.launch(debug=
|
|
|
4 |
import os
|
5 |
import tempfile
|
6 |
import shlex
|
7 |
+
from huggingface_hub import HfApi, HfHubHTTPError # Import HfHubHTTPError
|
8 |
|
9 |
from build_logic import (
|
10 |
_get_api_token as build_logic_get_api_token,
|
|
|
460 |
elif change["type"] == "CREATE_PR":
|
461 |
md_summary.append(f"- **🤝 Create Pull Request:** From `{change.get('source_repo_id', '...')}` to `{change.get('target_repo_id', '...')}`")
|
462 |
md_summary.append(f" - Title: `{change.get('title', '...')}`")
|
463 |
+
if change.get('body'): md_summary.append(f" - Body: `{change.get('body', '...')[:100]}{'...' if len(change.get('comment', '')) > 100 else ''}`")
|
464 |
elif change["type"] == "ADD_COMMENT":
|
465 |
md_summary.append(f"- **💬 Add Comment:** On `{change.get('repo_id', '...')}`")
|
466 |
md_summary.append(f" - Comment: `{change.get('comment', '...')[:100]}{'...' if len(change.get('comment', '')) > 100 else ''}`")
|
|
|
944 |
|
945 |
file_browser_update = gr.update(visible=True, choices=sorted(refreshed_file_list or []), value=None)
|
946 |
|
947 |
+
iframe_update = gr.update(value=None, visible=False) # Default to hidden
|
948 |
if owner_name and space_name:
|
949 |
sub_owner = re.sub(r'[^a-z0-9\-]+', '-', owner_name.lower()).strip('-') or 'owner'
|
950 |
sub_repo = re.sub(r'[^a-z0-9\-]+', '-', space_name.lower()).strip('-') or 'space'
|
951 |
iframe_url = f"https://{sub_owner}-{sub_repo}{'.static.hf.space' if sdk == 'static' else '.hf.space'}"
|
952 |
iframe_update = gr.update(value=f'<iframe src="{iframe_url}?__theme=light&embed=true" width="100%" height="500px"></iframe>', visible=True)
|
953 |
+
|
|
|
954 |
|
955 |
runtime_status_md = handle_refresh_space_status(hf_api_key, owner_name, space_name)
|
956 |
runtime_status_update = gr.update(value=runtime_status_md)
|
|
|
1001 |
selected_value = default_model if default_model in models else (models[0] if models else None)
|
1002 |
return gr.update(choices=models, value=selected_value)
|
1003 |
|
1004 |
+
def handle_detect_user(hf_api_key_ui, ui_owner_name_hint):
|
1005 |
# Outputs for detect_user_button.click (3 outputs)
|
1006 |
# [status_output, owner_name_input, list_spaces_display]
|
1007 |
|
|
|
1023 |
owner_update = gr.update(value=owner_name)
|
1024 |
|
1025 |
# Immediately trigger listing spaces using the detected owner
|
1026 |
+
# Assuming build_logic_list_user_spaces returns (list_of_space_names, error_string)
|
1027 |
+
spaces_list, list_err = build_logic_list_user_spaces(hf_api_key=token, owner=owner_name) # Pass token directly
|
1028 |
+
|
1029 |
if list_err:
|
1030 |
list_spaces_update = gr.update(value=f"List Spaces Error: {list_err}")
|
1031 |
_status += f" | List Spaces Error: {list_err}"
|
1032 |
else:
|
1033 |
+
# Format the list of spaces into a markdown string here
|
1034 |
+
if not spaces_list:
|
1035 |
+
list_spaces_md = f"*No spaces found for user/org `{owner_name}`.*"
|
1036 |
+
else:
|
1037 |
+
list_spaces_md = f"### Spaces for `{owner_name}`\n"
|
1038 |
+
for space in sorted(spaces_list):
|
1039 |
+
list_spaces_md += f"- `{space}`\n"
|
1040 |
+
|
1041 |
+
list_spaces_update = gr.update(value=list_spaces_md) # Pass the formatted markdown string
|
1042 |
|
1043 |
yield gr.update(value=_status), owner_update, list_spaces_update
|
1044 |
|
|
|
1281 |
try:
|
1282 |
api.create_repo(repo_id=repo_id_target, repo_type="space", space_sdk=space_sdk_ui, private=is_private_ui, exist_ok=True)
|
1283 |
build_status_messages.append(f"CREATE_SPACE: Successfully created or ensured space [{repo_id_target}](https://huggingface.co/spaces/{repo_id_target}) exists.")
|
1284 |
+
except HfHubHTTPError as e_http:
|
1285 |
+
msg = f"CREATE_SPACE HTTP Error ({e_http.response.status_code if e_http.response else 'N/A'}): {e_http.response.text if e_http.response else str(e_http)}. Check logs."
|
1286 |
+
build_status_messages.append(msg)
|
1287 |
+
errors_occurred = True
|
1288 |
+
if e_http.response and e_http.response.status_code in (401, 403):
|
1289 |
+
_build_status = f"Build Error: {msg}. Cannot proceed with file upload."; yield ( gr.update(value=_build_status), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() ); return
|
1290 |
except Exception as e:
|
1291 |
msg = f"CREATE_SPACE Error: {e}"
|
1292 |
build_status_messages.append(msg)
|
1293 |
errors_occurred = True
|
1294 |
+
_build_status = f"Build Error: {msg}. Cannot proceed with file upload."; yield ( gr.update(value=_build_status), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() ); return
|
|
|
1295 |
|
1296 |
_build_status = " | ".join(build_status_messages)
|
1297 |
yield ( gr.update(value=_build_status), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update() )
|
|
|
1506 |
log_link = status_details.get('full_log_link')
|
1507 |
if log_link and log_link != "#": md_lines.append(f"- [View Full Logs]({log_link})\n")
|
1508 |
# Add build logs link if available (common pattern in Space status)
|
1509 |
+
if ui_owner_name and ui_space_name:
|
|
|
|
|
1510 |
build_logs_url = f"https://huggingface.co/spaces/{ui_owner_name}/{ui_space_name}/build-logs"
|
1511 |
md_lines.append(f"- [View Build Logs]({build_logs_url})\n")
|
1512 |
|
|
|
1518 |
elif repo_info:
|
1519 |
md_lines.append(f"- **SDK:** `{repo_info.get('sdk', 'N/A')}`\n")
|
1520 |
md_lines.append(f"- **File Count:** `{repo_info.get('file_count', 'N/A')}`\n")
|
1521 |
+
if ui_owner_name and ui_space_name: # Add repo link
|
1522 |
repo_url = f"https://huggingface.co/spaces/{ui_owner_name}/{ui_space_name}/tree/main"
|
1523 |
md_lines.append(f"- [View Repository Files]({repo_url})\n")
|
1524 |
|
|
|
1640 |
|
1641 |
else: # If duplication had errors, don't attempt reload of new space, stay on current
|
1642 |
reload_error = "Reload skipped due to duplication errors."
|
1643 |
+
# Need to re-generate _formatted, _detected, _download based on source space if errors occurred
|
1644 |
+
_formatted, _detected, _download = _generate_ui_outputs_from_cache(source_owner, source_space_name)
|
1645 |
_file_browser_update = gr.update() # Keep current file browser state
|
1646 |
_iframe_html_update = gr.update() # Keep current iframe state
|
1647 |
runtime_status_update = handle_refresh_space_status(hf_api_key_ui, source_owner, source_space_name) # Refresh status of source space
|
1648 |
new_owner = source_owner # Revert fields to source space
|
1649 |
new_space_name = source_space_name
|
|
|
|
|
1650 |
|
1651 |
|
1652 |
# Generate final UI based on successful/failed reload
|
|
|
1798 |
|
1799 |
provider_select.change(update_models_dropdown, inputs=provider_select, outputs=model_select)
|
1800 |
|
1801 |
+
chat_inputs = [
|
1802 |
+
chat_message_input, chatbot_display, hf_api_key_input,
|
1803 |
+
provider_api_key_input, provider_select, model_select, system_prompt_input,
|
1804 |
+
owner_name_input, space_name_input
|
1805 |
+
] # 9 inputs
|
1806 |
+
chat_outputs = [
|
1807 |
+
chat_message_input, chatbot_display, status_output,
|
1808 |
+
detected_files_preview, formatted_space_output_display, download_button,
|
1809 |
+
changeset_state, changeset_display, confirm_accordion, confirm_button, cancel_button
|
1810 |
+
] # 11 outputs
|
1811 |
|
1812 |
send_chat_button.click(handle_chat_submit, inputs=chat_inputs, outputs=chat_outputs)
|
1813 |
chat_message_input.submit(handle_chat_submit, inputs=chat_inputs, outputs=chat_outputs)
|
1814 |
|
1815 |
confirm_inputs = [hf_api_key_input, owner_name_input, space_name_input, changeset_state] # 4 inputs
|
1816 |
+
confirm_outputs = [
|
1817 |
+
status_output, formatted_space_output_display, detected_files_preview, download_button,
|
1818 |
+
confirm_accordion, confirm_button, cancel_button, changeset_state, changeset_display,
|
1819 |
+
owner_name_input, space_name_input, file_browser_dropdown, space_iframe_display, space_runtime_status_display
|
1820 |
+
] # 14 outputs
|
1821 |
confirm_button.click(handle_confirm_changes, inputs=confirm_inputs, outputs=confirm_outputs)
|
1822 |
|
1823 |
+
cancel_outputs = [
|
1824 |
+
status_output, changeset_state, changeset_display,
|
1825 |
+
confirm_accordion, confirm_button, cancel_button
|
1826 |
+
] # 6 outputs
|
1827 |
cancel_button.click(handle_cancel_changes, inputs=None, outputs=cancel_outputs)
|
1828 |
|
1829 |
+
load_space_outputs = [
|
1830 |
+
formatted_space_output_display, detected_files_preview, status_output, file_browser_dropdown,
|
1831 |
+
owner_name_input, space_name_input, space_iframe_display, download_button, build_status_display,
|
1832 |
+
edit_status_display, space_runtime_status_display, changeset_state, changeset_display, confirm_accordion,
|
1833 |
+
confirm_button, cancel_button, list_spaces_display, target_owner_input, target_space_name_input, target_private_checkbox
|
1834 |
+
] # 20 outputs
|
1835 |
load_space_button.click(
|
1836 |
fn=handle_load_existing_space,
|
1837 |
inputs=[hf_api_key_input, owner_name_input, space_name_input], # 3 inputs
|
|
|
1839 |
)
|
1840 |
|
1841 |
detect_user_outputs = [status_output, owner_name_input, list_spaces_display] # 3 outputs
|
1842 |
+
# Pass owner_name_input to the detect user function, although it's not strictly needed for the logic,
|
1843 |
+
# it matches the function signature and allows initial yield to show the value.
|
1844 |
detect_user_button.click(fn=handle_detect_user, inputs=[hf_api_key_input, owner_name_input], outputs=detect_user_outputs) # 2 inputs
|
1845 |
|
1846 |
+
build_outputs = [
|
1847 |
+
build_status_display, space_iframe_display, file_browser_dropdown,
|
1848 |
+
owner_name_input, space_name_input,
|
1849 |
+
changeset_state, changeset_display, confirm_accordion, confirm_button, cancel_button,
|
1850 |
+
formatted_space_output_display, detected_files_preview, download_button, space_runtime_status_display
|
1851 |
+
] # 14 outputs
|
1852 |
+
build_inputs = [
|
1853 |
+
hf_api_key_input, space_name_input, owner_name_input, space_sdk_select,
|
1854 |
+
space_private_checkbox, formatted_space_output_display
|
1855 |
+
] # 6 inputs
|
1856 |
build_space_button.click(fn=handle_build_space_button, inputs=build_inputs, outputs=build_outputs)
|
1857 |
|
1858 |
+
# file_edit_load_outputs = [file_content_editor, edit_status_display, commit_message_input] # Corrected: 3 outputs
|
1859 |
file_browser_dropdown.change(
|
1860 |
fn=handle_load_file_for_editing,
|
1861 |
inputs=[hf_api_key_input, space_name_input, owner_name_input, file_browser_dropdown], # 4 inputs
|
1862 |
+
outputs=[file_content_editor, edit_status_display, commit_message_input] # Pass outputs explicitly here
|
1863 |
)
|
1864 |
|
1865 |
+
# commit_file_outputs = [edit_status_display, file_browser_dropdown, formatted_space_output_display, detected_files_preview, download_button] # 5 outputs
|
1866 |
update_file_button.click(
|
1867 |
fn=handle_commit_file_changes,
|
1868 |
inputs=[hf_api_key_input, space_name_input, owner_name_input, file_browser_dropdown, file_content_editor, commit_message_input], # 6 inputs
|
1869 |
outputs=commit_file_outputs
|
1870 |
)
|
1871 |
|
1872 |
+
# delete_file_outputs = [edit_status_display, file_browser_dropdown, file_content_editor, commit_message_input,
|
1873 |
+
# formatted_space_output_display, detected_files_preview, download_button] # Corrected: 7 outputs
|
1874 |
delete_file_button.click(
|
1875 |
fn=handle_delete_file,
|
1876 |
inputs=[hf_api_key_input, space_name_input, owner_name_input, file_browser_dropdown], # 4 inputs
|
1877 |
+
outputs=[
|
1878 |
+
edit_status_display, file_browser_dropdown,
|
1879 |
+
file_content_editor, commit_message_input, # Clear editor fields
|
1880 |
+
formatted_space_output_display, detected_files_preview, download_button # Update displays
|
1881 |
+
] # Pass outputs explicitly here
|
1882 |
)
|
1883 |
|
1884 |
refresh_status_button.click(fn=handle_refresh_space_status, inputs=[hf_api_key_input, owner_name_input, space_name_input], outputs=[space_runtime_status_display]) # 3 inputs, 1 output
|
1885 |
|
1886 |
+
# manual_duplicate_inputs = [hf_api_key_input, owner_name_input, space_name_input, target_owner_input, target_space_name_input, target_private_checkbox] # 6 inputs
|
1887 |
+
# manual_duplicate_outputs = [status_output, owner_name_input, space_name_input,
|
1888 |
+
# formatted_space_output_display, detected_files_preview, download_button,
|
1889 |
+
# file_browser_dropdown, space_iframe_display, space_runtime_status_display] # 9 outputs
|
1890 |
duplicate_space_button.click(fn=handle_manual_duplicate_space, inputs=manual_duplicate_inputs, outputs=manual_duplicate_outputs)
|
1891 |
|
1892 |
list_spaces_button.click(fn=handle_list_spaces, inputs=[hf_api_key_input, owner_name_input], outputs=[list_spaces_display]) # 2 inputs, 1 output
|
1893 |
|
1894 |
|
1895 |
if __name__ == "__main__":
|
1896 |
+
demo.launch(debug=True, mcp_server=True) # Set debug=True for more detailed errors
|