Spaces:
Sleeping
Sleeping
Download app.py from Thaimozhi/Go-Filter-Bot: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/spaces/Thaimozhi/Go-Filter-Bot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Thaimozhi/Go-Filter-Bot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Thaimozhi/Go-Filter-Bot/resolve/main/app.py
2.09 kB
| import os | |
| import shutil | |
| import subprocess | |
| import urllib.request | |
| import tarfile | |
| import gradio as gr | |
| try: | |
| import spaces | |
| def dummy_gpu_fn(): | |
| pass | |
| except Exception: | |
| pass | |
| def ensure_go(): | |
| if shutil.which("go"): | |
| print("Go compiler found in system PATH.") | |
| return "go" | |
| go_bin = os.path.abspath("go_dist/bin/go") | |
| if os.path.exists(go_bin): | |
| print(f"Go compiler found at {go_bin}") | |
| return go_bin | |
| print("Downloading Go compiler (go1.21.6)...") | |
| url = "https://go.dev/dl/go1.21.6.linux-amd64.tar.gz" | |
| tar_path = "/tmp/go.tar.gz" | |
| urllib.request.urlretrieve(url, tar_path) | |
| print("Extracting Go...") | |
| os.makedirs("go_dist", exist_ok=True) | |
| with tarfile.open(tar_path, "r:gz") as tar: | |
| tar.extractall(path="go_dist_temp") | |
| if os.path.exists("go_dist_temp/go"): | |
| shutil.rmtree("go_dist", ignore_errors=True) | |
| os.rename("go_dist_temp/go", "go_dist") | |
| shutil.rmtree("go_dist_temp", ignore_errors=True) | |
| if os.path.exists(tar_path): | |
| os.remove(tar_path) | |
| return go_bin | |
| # Setup Go environment & PATH | |
| go_cmd = ensure_go() | |
| env = os.environ.copy() | |
| if os.path.exists(os.path.abspath("go_dist/bin")): | |
| env["PATH"] = os.path.abspath("go_dist/bin") + ":" + env.get("PATH", "") | |
| # Set Go bot internal HTTP port to 8080 to prevent collision with Gradio (7860 & 7861) | |
| env["PORT"] = "8080" | |
| # Build Go Bot binary | |
| print("Building Go-Filter-Bot binary...") | |
| subprocess.run([go_cmd, "build", "-o", "Go-Filter-Bot", "."], check=True, env=env) | |
| # Run Go Bot binary in background | |
| print("Starting Go-Filter-Bot process...") | |
| bot_process = subprocess.Popen(["./Go-Filter-Bot"], env=env) | |
| # Create Gradio interface for HF Space supervisor | |
| with gr.Blocks(title="Telegram Go Filter Bot") as demo: | |
| gr.Markdown(""" | |
| # 🤖 Telegram Auto-Filter Bot | |
| ### Status: Online 24/7 🚀 | |
| The bot is active and processing updates in the background. | |
| """) | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False) | |