Spaces:
Running
Running
auto deploy fix
Browse files- backend_api.py +34 -2
backend_api.py
CHANGED
|
@@ -835,7 +835,25 @@ async def generate_code(
|
|
| 835 |
from backend_deploy import deploy_to_huggingface_space
|
| 836 |
|
| 837 |
# Convert history to the format expected by deploy function
|
| 838 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 839 |
|
| 840 |
# Deploy the code
|
| 841 |
success, message, space_url = deploy_to_huggingface_space(
|
|
@@ -846,6 +864,11 @@ async def generate_code(
|
|
| 846 |
history=history_list
|
| 847 |
)
|
| 848 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 849 |
if success and space_url:
|
| 850 |
# Send deployment success
|
| 851 |
deploy_success_data = json.dumps({
|
|
@@ -863,12 +886,21 @@ async def generate_code(
|
|
| 863 |
yield f"data: {deploy_error_data}\n\n"
|
| 864 |
except Exception as deploy_error:
|
| 865 |
# Log deployment error but don't fail the generation
|
| 866 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 867 |
deploy_error_data = json.dumps({
|
| 868 |
"type": "deploy_error",
|
| 869 |
"message": f"⚠️ Deployment error: {str(deploy_error)}"
|
| 870 |
})
|
| 871 |
yield f"data: {deploy_error_data}\n\n"
|
|
|
|
|
|
|
| 872 |
|
| 873 |
except Exception as e:
|
| 874 |
# Handle rate limiting and other API errors
|
|
|
|
| 835 |
from backend_deploy import deploy_to_huggingface_space
|
| 836 |
|
| 837 |
# Convert history to the format expected by deploy function
|
| 838 |
+
# History comes from frontend as [[role, content], ...]
|
| 839 |
+
history_list = []
|
| 840 |
+
if request.history:
|
| 841 |
+
for msg in request.history:
|
| 842 |
+
if isinstance(msg, list) and len(msg) >= 2:
|
| 843 |
+
# Already in correct format [[role, content], ...]
|
| 844 |
+
history_list.append([msg[0], msg[1]])
|
| 845 |
+
elif isinstance(msg, dict):
|
| 846 |
+
# Convert dict format to list format
|
| 847 |
+
role = msg.get('role', '')
|
| 848 |
+
content = msg.get('content', '')
|
| 849 |
+
if role and content:
|
| 850 |
+
history_list.append([role, content])
|
| 851 |
+
|
| 852 |
+
print(f"[Auto-Deploy] Starting deployment...")
|
| 853 |
+
print(f"[Auto-Deploy] - Language: {language}")
|
| 854 |
+
print(f"[Auto-Deploy] - History items: {len(history_list)}")
|
| 855 |
+
print(f"[Auto-Deploy] - Username: {auth.username}")
|
| 856 |
+
print(f"[Auto-Deploy] - Code length: {len(generated_code)}")
|
| 857 |
|
| 858 |
# Deploy the code
|
| 859 |
success, message, space_url = deploy_to_huggingface_space(
|
|
|
|
| 864 |
history=history_list
|
| 865 |
)
|
| 866 |
|
| 867 |
+
print(f"[Auto-Deploy] Deployment result:")
|
| 868 |
+
print(f"[Auto-Deploy] - Success: {success}")
|
| 869 |
+
print(f"[Auto-Deploy] - Message: {message}")
|
| 870 |
+
print(f"[Auto-Deploy] - Space URL: {space_url}")
|
| 871 |
+
|
| 872 |
if success and space_url:
|
| 873 |
# Send deployment success
|
| 874 |
deploy_success_data = json.dumps({
|
|
|
|
| 886 |
yield f"data: {deploy_error_data}\n\n"
|
| 887 |
except Exception as deploy_error:
|
| 888 |
# Log deployment error but don't fail the generation
|
| 889 |
+
import traceback
|
| 890 |
+
print(f"[Auto-Deploy] ========== DEPLOYMENT EXCEPTION ==========")
|
| 891 |
+
print(f"[Auto-Deploy] Exception type: {type(deploy_error).__name__}")
|
| 892 |
+
print(f"[Auto-Deploy] Error message: {str(deploy_error)}")
|
| 893 |
+
print(f"[Auto-Deploy] Full traceback:")
|
| 894 |
+
traceback.print_exc()
|
| 895 |
+
print(f"[Auto-Deploy] ==========================================")
|
| 896 |
+
|
| 897 |
deploy_error_data = json.dumps({
|
| 898 |
"type": "deploy_error",
|
| 899 |
"message": f"⚠️ Deployment error: {str(deploy_error)}"
|
| 900 |
})
|
| 901 |
yield f"data: {deploy_error_data}\n\n"
|
| 902 |
+
else:
|
| 903 |
+
print(f"[Auto-Deploy] Skipped - authenticated: {auth.is_authenticated()}, token_exists: {auth.token is not None}, is_dev: {auth.token.startswith('dev_token_') if auth.token else False}")
|
| 904 |
|
| 905 |
except Exception as e:
|
| 906 |
# Handle rate limiting and other API errors
|