Deploy Bot commited on
Commit
5cf0eef
·
1 Parent(s): 60a0e7f

Add health server for HuggingFace Spaces (port 7860)

Browse files
Files changed (2) hide show
  1. Dockerfile +4 -1
  2. app.py +32 -0
Dockerfile CHANGED
@@ -13,4 +13,7 @@ RUN mkdir -p /data
13
  # Set logging to stdout for container logs
14
  ENV PYTHONUNBUFFERED=1
15
 
16
- CMD ["python", "bot.py"]
 
 
 
 
13
  # Set logging to stdout for container logs
14
  ENV PYTHONUNBUFFERED=1
15
 
16
+ # HuggingFace Spaces requires port 7860
17
+ EXPOSE 7860
18
+
19
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ MTXtyle Bot - Hugging Face Spaces Entry Point
3
+ Runs a simple HTTP health server on port 7860 (required by HF)
4
+ and starts the Telegram bot in a background thread.
5
+ """
6
+ import threading
7
+ from http.server import HTTPServer, BaseHTTPRequestHandler
8
+ import subprocess
9
+ import sys
10
+
11
+ class HealthHandler(BaseHTTPRequestHandler):
12
+ def do_GET(self):
13
+ self.send_response(200)
14
+ self.send_header("Content-type", "text/html; charset=utf-8")
15
+ self.end_headers()
16
+ self.wfile.write("🤖 MTXtyle Bot is running!".encode("utf-8"))
17
+
18
+ def log_message(self, format, *args):
19
+ pass # Suppress logs
20
+
21
+ def run_bot():
22
+ subprocess.run([sys.executable, "bot.py"])
23
+
24
+ if __name__ == "__main__":
25
+ # Start bot in background thread
26
+ bot_thread = threading.Thread(target=run_bot, daemon=True)
27
+ bot_thread.start()
28
+
29
+ # Start health server on port 7860 (required by HuggingFace)
30
+ server = HTTPServer(("0.0.0.0", 7860), HealthHandler)
31
+ print("🌐 Health server running on port 7860")
32
+ server.serve_forever()