Spaces:
Runtime error
Runtime error
Download app.py from behaviour01/deep_learning: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/behaviour01/deep_learning/resolve/ff71fd763aa11221334e97ee052d5c19239625cb/app.py
- Command line
-
hf download hf://spaces/behaviour01/deep_learning@ff71fd763aa11221334e97ee052d5c19239625cb/app.py
-
curl -L -o app.py https://huggingface.co/spaces/behaviour01/deep_learning/resolve/ff71fd763aa11221334e97ee052d5c19239625cb/app.py
1.17 kB
| import os | |
| import threading | |
| import requests | |
| from flask import Flask | |
| from telegram.ext import Application, CommandHandler | |
| TELEGRAM_BOT_TOKEN = "7799719627:AAFz7gF74OeajbUqqb4ZJcsJPzal8R8NN3o" | |
| async def get_real_region(): | |
| try: | |
| res = requests.get("https://ipapi.co/json/ ", timeout=5) | |
| data = res.json() | |
| return f"{data.get('country_name', '')}, {data.get('region', '')}" | |
| except Exception: | |
| return "Unknown location" | |
| async def region_command(update, context): | |
| await update.message.reply_text(f"📍 This bot is running in: {await get_real_region()}") | |
| def start_telegram_bot(): | |
| app = Application.builder().token(TELEGRAM_BOT_TOKEN).build() | |
| app.add_handler(CommandHandler("region", region_command)) | |
| app.run_polling() | |
| # === Flask Web App (port 7860) === | |
| app = Flask(__name__) | |
| def home(): | |
| return "Bot is running. Send /region to Telegram bot." | |
| if __name__ == "__main__": | |
| # Start Telegram bot in background | |
| bot_thread = threading.Thread(target=start_telegram_bot) | |
| bot_thread.daemon = True | |
| bot_thread.start() | |
| # Run Flask on main thread | |
| app.run(host="0.0.0.0", port=7860) |