Spaces:
Running
Running
Foydalanuvchi commited on
Commit ·
79aad23
1
Parent(s): 871edc7
Add HTTP server for Hugging Face health check
Browse files
main.py
CHANGED
|
@@ -394,8 +394,26 @@ async def button_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
| 394 |
# Xotirani majburiy tozalash (RAM to'lishini oldini oladi)
|
| 395 |
gc.collect()
|
| 396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
if __name__ == '__main__':
|
| 398 |
if TOKEN:
|
|
|
|
|
|
|
| 399 |
app = ApplicationBuilder().token(TOKEN).post_init(post_init).build()
|
| 400 |
app.add_handler(CommandHandler("start", start))
|
| 401 |
app.add_handler(CallbackQueryHandler(navigation_handler, pattern=r"^nav\|"))
|
|
@@ -403,5 +421,5 @@ if __name__ == '__main__':
|
|
| 403 |
app.add_handler(CallbackQueryHandler(button_handler))
|
| 404 |
app.add_handler(MessageHandler(filters.PHOTO, handle_photo))
|
| 405 |
app.add_handler(MessageHandler(filters.VIDEO | filters.ANIMATION | filters.Document.ALL, handle_video))
|
| 406 |
-
print("Bot ishga tushdi...")
|
| 407 |
app.run_polling()
|
|
|
|
| 394 |
# Xotirani majburiy tozalash (RAM to'lishini oldini oladi)
|
| 395 |
gc.collect()
|
| 396 |
|
| 397 |
+
import threading
|
| 398 |
+
from http.server import BaseHTTPRequestHandler, HTTPServer
|
| 399 |
+
|
| 400 |
+
class HealthCheckHandler(BaseHTTPRequestHandler):
|
| 401 |
+
def do_GET(self):
|
| 402 |
+
self.send_response(200)
|
| 403 |
+
self.send_header("Content-type", "text/html")
|
| 404 |
+
self.end_headers()
|
| 405 |
+
self.wfile.write(b"Bot ishlamoqda!")
|
| 406 |
+
def log_message(self, format, *args):
|
| 407 |
+
pass
|
| 408 |
+
|
| 409 |
+
def run_dummy_server():
|
| 410 |
+
server = HTTPServer(("0.0.0.0", 7860), HealthCheckHandler)
|
| 411 |
+
server.serve_forever()
|
| 412 |
+
|
| 413 |
if __name__ == '__main__':
|
| 414 |
if TOKEN:
|
| 415 |
+
threading.Thread(target=run_dummy_server, daemon=True).start()
|
| 416 |
+
|
| 417 |
app = ApplicationBuilder().token(TOKEN).post_init(post_init).build()
|
| 418 |
app.add_handler(CommandHandler("start", start))
|
| 419 |
app.add_handler(CallbackQueryHandler(navigation_handler, pattern=r"^nav\|"))
|
|
|
|
| 421 |
app.add_handler(CallbackQueryHandler(button_handler))
|
| 422 |
app.add_handler(MessageHandler(filters.PHOTO, handle_photo))
|
| 423 |
app.add_handler(MessageHandler(filters.VIDEO | filters.ANIMATION | filters.Document.ALL, handle_video))
|
| 424 |
+
print("Bot ishga tushdi va 7860 portda server faol...")
|
| 425 |
app.run_polling()
|