import shutil import subprocess import sys from pathlib import Path from dotenv import load_dotenv REPO_URL = "https://github.com/tuteishygpt/check-dataset.git" REPO_BRANCH = "main" REPO_DIR = Path("/tmp/check-dataset") def run_cmd(cmd, cwd=None): subprocess.run( cmd, cwd=str(cwd) if cwd else None, check=True, ) def clone_repo(): REPO_DIR.parent.mkdir(parents=True, exist_ok=True) run_cmd([ "git", "clone", "--depth", "1", "--branch", REPO_BRANCH, REPO_URL, str(REPO_DIR), ]) def update_repo(): run_cmd(["git", "fetch", "origin", REPO_BRANCH, "--depth", "1"], cwd=REPO_DIR) run_cmd(["git", "reset", "--hard", f"origin/{REPO_BRANCH}"], cwd=REPO_DIR) run_cmd(["git", "clean", "-fd"], cwd=REPO_DIR) def ensure_repo(): if not REPO_DIR.exists(): clone_repo() return if not (REPO_DIR / ".git").exists(): shutil.rmtree(REPO_DIR, ignore_errors=True) clone_repo() return try: update_repo() except Exception: shutil.rmtree(REPO_DIR, ignore_errors=True) clone_repo() ensure_repo() repo_root = str(REPO_DIR.resolve()) if repo_root not in sys.path: sys.path.insert(0, repo_root) # Падцягнуць .env, калі ён ёсць у кланаваным рэпо; # плюс звычайныя env-пераменныя Space таксама застануцца даступныя load_dotenv(REPO_DIR / ".env") load_dotenv() from ui.gradio_app import create_interface # noqa: E402 # ВАЖНА: global demo для Gradio hot reload demo = create_interface() if __name__ == "__main__": demo.launch( server_name="0.0.0.0", server_port=7860, debug=True, show_error=True, ssr_mode=False, )