Kai Izumoto commited on
Commit
4c63a0d
·
verified ·
1 Parent(s): 248cac4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -19,6 +19,10 @@ from datetime import datetime
19
  import gradio as gr
20
  from huggingface_hub import InferenceClient
21
 
 
 
 
 
22
  # ---------- Config ----------
23
  PYTHON_MODEL = "Nxcode-CQ-7B-orpo"
24
  OTHER_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
@@ -73,20 +77,21 @@ def get_token_from_env_or_manual(manual_token: Optional[str]) -> Optional[str]:
73
  return manual_token.strip()
74
  return os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
75
 
76
- def detect_language(goal: str, code: str) -> str:
77
- """Detects if the project is primarily Python or another language."""
78
- combined = (goal + " " + code).lower()
 
 
79
  python_kw = ["python", "django", "flask", "fastapi", "pytest", "def ", "import ", "pip"]
80
- if any(kw in combined for kw in python_kw):
81
- return "python"
82
- return "other"
83
 
84
  def run_cmd(cmd: List[str], cwd: Optional[str] = None, timeout: int = COMMAND_TIMEOUT) -> Tuple[int, str]:
85
  """Runs a command in a subprocess with a timeout and captures output."""
86
  try:
87
  # Sandboxed execution: disable network for pytest
88
  env = os.environ.copy()
89
- if "pytest" in cmd[0]:
 
90
  env["ALLOW_NETWORK"] = "0"
91
 
92
  proc = subprocess.run(
@@ -575,7 +580,8 @@ def create_ui():
575
  with gr.TabItem("tests/test_main.py"):
576
  test_file = gr.Code(language="python", lines=15)
577
  with gr.TabItem("requirements.txt"):
578
- req_file = gr.Code(language="text", lines=10)
 
579
  with gr.TabItem("README.md"):
580
  readme_file = gr.Code(language="markdown", lines=15)
581
  with gr.TabItem("Other Files"):
@@ -640,4 +646,4 @@ if __name__ == "__main__":
640
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)
641
  except Exception as e:
642
  print(f"Failed to launch Gradio app: {e}", file=sys.stderr)
643
- sys.exit(1)
 
19
  import gradio as gr
20
  from huggingface_hub import InferenceClient
21
 
22
+ # Added missing imports
23
+ import tempfile
24
+ import zipfile
25
+
26
  # ---------- Config ----------
27
  PYTHON_MODEL = "Nxcode-CQ-7B-orpo"
28
  OTHER_MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct"
 
77
  return manual_token.strip()
78
  return os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
79
 
80
+ def detect_language(goal: str, code: str) -> bool:
81
+ """Detects whether the project is primarily Python.
82
+ Returns True for Python, False otherwise.
83
+ """
84
+ combined = (goal + " " + (code or "")).lower()
85
  python_kw = ["python", "django", "flask", "fastapi", "pytest", "def ", "import ", "pip"]
86
+ return any(kw in combined for kw in python_kw)
 
 
87
 
88
  def run_cmd(cmd: List[str], cwd: Optional[str] = None, timeout: int = COMMAND_TIMEOUT) -> Tuple[int, str]:
89
  """Runs a command in a subprocess with a timeout and captures output."""
90
  try:
91
  # Sandboxed execution: disable network for pytest
92
  env = os.environ.copy()
93
+ # If command references pytest explicitly, disable network for safety
94
+ if any("pytest" in str(part) for part in cmd):
95
  env["ALLOW_NETWORK"] = "0"
96
 
97
  proc = subprocess.run(
 
580
  with gr.TabItem("tests/test_main.py"):
581
  test_file = gr.Code(language="python", lines=15)
582
  with gr.TabItem("requirements.txt"):
583
+ # Changed language from "text" (unsupported) to "ini"
584
+ req_file = gr.Code(language="ini", lines=10)
585
  with gr.TabItem("README.md"):
586
  readme_file = gr.Code(language="markdown", lines=15)
587
  with gr.TabItem("Other Files"):
 
646
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)
647
  except Exception as e:
648
  print(f"Failed to launch Gradio app: {e}", file=sys.stderr)
649
+ sys.exit(1)