from fastapi import FastAPI from fastapi.responses import HTMLResponse import uvicorn import subprocess import threading from pathlib import Path app = FastAPI() count_file = Path("/tmp/people_helped.txt") count_file.write_text("0") def increment_count(): current = int(count_file.read_text().strip() or "0") count_file.write_text(str(current + 1)) print(f"✅ Counter increased! New total: {current + 1}") def monitor_snowflake(): print("Starting Snowflake proxy and monitoring...") proc = subprocess.Popen( ["snowflake-proxy", "-verbose", "-relay", "https://snowflake.torproject.org/"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1 ) for line in proc.stdout: line = line.strip() if not line: continue print(f"LOG: {line}") # This will show in HF Logs # Broader detection for client connections lower_line = line.lower() if any(x in lower_line for x in [ "client connected", "accepted connection", "new session", "webrtc: peerconnection", "data channel opened", "proxy: client", "established connection", "starting session" ]): increment_count() # Start monitoring threading.Thread(target=monitor_snowflake, daemon=True).start() @app.get("/", response_class=HTMLResponse) async def dashboard(): count = count_file.read_text().strip() return f"""
People I've helped today:
Proxy is running 24/7
""" @app.get("/count") async def get_count(): return {"count": int(count_file.read_text().strip() or "0")} if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=7860)