Delete deployment.py
Browse files- deployment.py +0 -44
deployment.py
DELETED
@@ -1,44 +0,0 @@
|
|
1 |
-
# /deployment.py
|
2 |
-
""" Handles deployment of generated code to Hugging Face Spaces. """
|
3 |
-
import logging
|
4 |
-
from huggingface_hub import HfApi
|
5 |
-
|
6 |
-
def deploy_to_hf_space(code: str, space_name: str, sdk: str, hf_token: str) -> str:
|
7 |
-
"""
|
8 |
-
Creates or updates a Hugging Face Space and uploads the generated code.
|
9 |
-
"""
|
10 |
-
if not code.strip():
|
11 |
-
return "Cannot deploy: No code has been generated."
|
12 |
-
if not space_name.strip():
|
13 |
-
return "Cannot deploy: Please provide a name for your app."
|
14 |
-
|
15 |
-
try:
|
16 |
-
api = HfApi(token=hf_token)
|
17 |
-
# Get the username associated with the token
|
18 |
-
username = api.whoami(token=hf_token)['name']
|
19 |
-
repo_id = f"{username}/{space_name.strip()}"
|
20 |
-
|
21 |
-
# Create the repository on the Hub
|
22 |
-
api.create_repo(repo_id, repo_type="space", space_sdk=sdk, exist_ok=True)
|
23 |
-
|
24 |
-
# Determine the correct filename based on the SDK
|
25 |
-
file_path_in_repo = "index.html" if sdk == 'static' else "app.py"
|
26 |
-
|
27 |
-
# Upload the generated code file
|
28 |
-
api.upload_file(
|
29 |
-
path_or_fileobj=code.encode('utf-8'),
|
30 |
-
path_in_repo=file_path_in_repo,
|
31 |
-
repo_id=repo_id,
|
32 |
-
repo_type="space"
|
33 |
-
)
|
34 |
-
|
35 |
-
# Construct the URL to the newly deployed Space
|
36 |
-
space_url = f"https://huggingface.co/spaces/{repo_id}"
|
37 |
-
|
38 |
-
# <--- FIX: The string literal is now correctly terminated ---
|
39 |
-
return f"✅ Deployed successfully! [Open your Space]({space_url})"
|
40 |
-
|
41 |
-
except Exception as e:
|
42 |
-
# Provide a more informative error message
|
43 |
-
logging.error(f"Failed to deploy to Hugging Face Space: {e}")
|
44 |
-
return f"❌ Deployment failed: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|