aiioe commited on
Commit
32ca700
ยท
verified ยท
1 Parent(s): e454383

Fixed env problem

Browse files
Dockerfile CHANGED
@@ -14,6 +14,5 @@ COPY out/ _backend/static/
14
  WORKDIR /app/_backend
15
  # Copy backend (after frontend build to maximize caching)
16
  COPY _backend/ .
17
- COPY .env .env
18
  EXPOSE 8000
19
  CMD ["python", "api_meeting_minutes.py"]
 
14
  WORKDIR /app/_backend
15
  # Copy backend (after frontend build to maximize caching)
16
  COPY _backend/ .
 
17
  EXPOSE 8000
18
  CMD ["python", "api_meeting_minutes.py"]
Dockerfile.generated CHANGED
@@ -14,6 +14,5 @@ COPY out/ _backend/static/
14
  WORKDIR /app/_backend
15
  # Copy backend (after frontend build to maximize caching)
16
  COPY _backend/ .
17
- COPY .env .env
18
  EXPOSE 8000
19
  CMD ["python", "api_meeting_minutes.py"]
 
14
  WORKDIR /app/_backend
15
  # Copy backend (after frontend build to maximize caching)
16
  COPY _backend/ .
 
17
  EXPOSE 8000
18
  CMD ["python", "api_meeting_minutes.py"]
_backend/cli/build_tool.py CHANGED
@@ -3,6 +3,9 @@ import sys
3
  import subprocess
4
  from pathlib import Path
5
  from typing import List
 
 
 
6
 
7
  sys.path.append(str(Path(__file__).resolve().parents[1])) # Add parent directory to path
8
 
@@ -149,7 +152,7 @@ def interactive(
149
  space_id = os.getenv("HF_SPACE_ID") or ("" if non_interactive else questionary.text(
150
  "Enter HF Space (user/space):"
151
  ).ask())
152
- token = os.getenv("HUGGINGFACE_TOKEN") or ("" if non_interactive else questionary.password(
153
  "Enter Hugging Face token:"
154
  ).ask())
155
  if not space_id or not token:
 
3
  import subprocess
4
  from pathlib import Path
5
  from typing import List
6
+ from dotenv import load_dotenv
7
+
8
+ load_dotenv()
9
 
10
  sys.path.append(str(Path(__file__).resolve().parents[1])) # Add parent directory to path
11
 
 
152
  space_id = os.getenv("HF_SPACE_ID") or ("" if non_interactive else questionary.text(
153
  "Enter HF Space (user/space):"
154
  ).ask())
155
+ token = os.getenv("HF_TOKEN") or ("" if non_interactive else questionary.password(
156
  "Enter Hugging Face token:"
157
  ).ask())
158
  if not space_id or not token:
_backend/cli/docker_builder.py CHANGED
@@ -22,7 +22,6 @@ WORKDIR /app/_backend
22
 
23
  BACKEND_COPY = """# Copy backend (after frontend build to maximize caching)
24
  COPY _backend/ .
25
- COPY .env .env
26
  """
27
 
28
  GRAPH_RAG_COPY_TEMPLATE = """# Include GraphRAG artifacts
 
22
 
23
  BACKEND_COPY = """# Copy backend (after frontend build to maximize caching)
24
  COPY _backend/ .
 
25
  """
26
 
27
  GRAPH_RAG_COPY_TEMPLATE = """# Include GraphRAG artifacts
_backend/cli/hf_deployer.py CHANGED
@@ -8,23 +8,39 @@ def deploy_space(space_id: str, source_dir: Path, token: str, private: bool = Fa
8
  def generate_dynamic_readme(title: str) -> str:
9
  return f'''---\ntitle: {title}\nemoji: ๐Ÿง‘โ€๐Ÿ’ผ\ncolorFrom: indigo\ncolorTo: blue\nsdk: docker\nsdk_version: "1.0"\napp_file: app.py\npinned: false\n---\n\n# {title}\n\nThis Space is deployed with a dynamic README.\n'''
10
 
11
- # Ask for a title interactively if not provided via env
12
  import questionary
 
 
 
 
 
 
13
  title = os.getenv("HF_SPACE_TITLE") or questionary.text("Enter Hugging Face Space title:", default="Interview Synthesizer").ask()
14
  dynamic_readme = generate_dynamic_readme(title)
15
- # Write to a temp file and copy to the repo root for upload
16
  with tempfile.NamedTemporaryFile("w", delete=False, encoding="utf-8", suffix=".md") as tmpf:
17
  tmpf.write(dynamic_readme)
18
  tmpf.flush()
19
  tmp_readme_path = Path(tmpf.name)
20
- # Copy to repo root as README.md (overwrite just for upload)
21
  import shutil
22
  shutil.copy(tmp_readme_path, source_dir / "README.md")
 
 
 
23
  api = HfApi()
24
  try:
25
  create_repo(space_id, repo_type="space", token=token, private=private, exist_ok=True)
26
  except Exception as e:
27
  print(f"Repo create/check warning: {e}")
 
 
 
 
 
 
 
 
 
 
28
 
29
  api.upload_folder(
30
  token=token,
@@ -32,6 +48,18 @@ def deploy_space(space_id: str, source_dir: Path, token: str, private: bool = Fa
32
  repo_type="space",
33
  folder_path=str(source_dir),
34
  path_in_repo=".",
35
- commit_message="Automated build & deploy",
36
  )
37
  print(f"Uploaded to https://huggingface.co/spaces/{space_id}")
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def generate_dynamic_readme(title: str) -> str:
9
  return f'''---\ntitle: {title}\nemoji: ๐Ÿง‘โ€๐Ÿ’ผ\ncolorFrom: indigo\ncolorTo: blue\nsdk: docker\nsdk_version: "1.0"\napp_file: app.py\npinned: false\n---\n\n# {title}\n\nThis Space is deployed with a dynamic README.\n'''
10
 
 
11
  import questionary
12
+ # Get token and space name from environment
13
+ space_id = os.getenv("HF_SPACE_ID")
14
+ token = os.getenv("HF_TOKEN")
15
+ if not space_id or not token:
16
+ raise RuntimeError("HF_SPACE_ID and HUGGINGFACE_TOKEN must be set in environment.")
17
+
18
  title = os.getenv("HF_SPACE_TITLE") or questionary.text("Enter Hugging Face Space title:", default="Interview Synthesizer").ask()
19
  dynamic_readme = generate_dynamic_readme(title)
 
20
  with tempfile.NamedTemporaryFile("w", delete=False, encoding="utf-8", suffix=".md") as tmpf:
21
  tmpf.write(dynamic_readme)
22
  tmpf.flush()
23
  tmp_readme_path = Path(tmpf.name)
 
24
  import shutil
25
  shutil.copy(tmp_readme_path, source_dir / "README.md")
26
+
27
+ # Prompt for commit message
28
+ commit_message = questionary.text("Commit message:", default="automated upload").ask()
29
  api = HfApi()
30
  try:
31
  create_repo(space_id, repo_type="space", token=token, private=private, exist_ok=True)
32
  except Exception as e:
33
  print(f"Repo create/check warning: {e}")
34
+ api.add_space_secret
35
+ try:
36
+ create_repo(space_id, repo_type="space", token=token, private=private, exist_ok=True, space_sdk="docker")
37
+ except Exception as e:
38
+ print(f"Repo create/check warning: {e}")
39
+
40
+ # Remove .env from upload if present
41
+ env_path = source_dir / ".env"
42
+ if env_path.exists():
43
+ env_path.unlink()
44
 
45
  api.upload_folder(
46
  token=token,
 
48
  repo_type="space",
49
  folder_path=str(source_dir),
50
  path_in_repo=".",
51
+ commit_message=commit_message
52
  )
53
  print(f"Uploaded to https://huggingface.co/spaces/{space_id}")
54
+
55
+ # Add secrets from environment to Space
56
+ for key in ["OPENAI_API_KEY", "ENVIRONMENT"]:
57
+ value = os.getenv(key)
58
+ if value:
59
+ api.add_space_secret(
60
+ repo_id=space_id,
61
+ key=key,
62
+ value=value,
63
+ description=f"Secret {key} for Space deployment",
64
+ token=token
65
+ )