Spaces:
Runtime error
Runtime error
Update bot.py
Browse files123456782 unmodified lines1112131415169 unmodified lines2627282930314 unmodified lines363738394041421 unmodified line44454647import osimport requestsfrom telegram import Updatefrom telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, ContextTypesTELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")NVIDIA_API_KEY = os.getenv("NVIDIA_API_KEY")2 unmodified linesasync def chat(update: Update, context: ContextTypes.DEFAULT_TYPE):user_message = update.message.texttry:response = requests.post("https://nvidia.com",9 unmodified lines},timeout=30)data = response.json()if "choices" in data and len(data["choices"]) > 0:ai_reply = data["choices"][0]["message"]["content"]4 unmodified linesawait update.message.reply_text(ai_reply)# Start the bot directly without the underscore checkif not TELEGRAM_TOKEN or not NVIDIA_API_KEY:print("β Error: Missing Environment Variables!")else:1 unmodified lineapp.add_handler(CommandHandler("start", start))app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, chat))print("π Nemotron 3 Super Bot is running...")app.run_polling()123456789102 unmodified lines131415161718199 unmodified lines293031323334354 unmodified lines404142434445461 unmodified line484950515253545556575859import osimport requestsimport asynciofrom telegram import Updatefrom telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, ContextTypes# Retrieve tokens securely from Hugging Face SecretsTELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")NVIDIA_API_KEY = os.getenv("NVIDIA_API_KEY")2 unmodified linesasync def chat(update: Update, context: ContextTypes.DEFAULT_TYPE):user_message = update.message.texttry:response = requests.post("https://nvidia.com",9 unmodified lines},timeout=30)data = response.json()if "choices" in data and len(data["choices"]) > 0:ai_reply = data["choices"][0]["message"]["content"]4 unmodified linesawait update.message.reply_text(ai_reply)# Start the bot directly with modern background runner compatibilityif not TELEGRAM_TOKEN or not NVIDIA_API_KEY:print("β Error: Missing Environment Variables!")else:1 unmodified lineapp.add_handler(CommandHandler("start", start))app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, chat))print("π Nemotron 3 Super Bot is running...")try:loop = asyncio.get_event_loop()if loop.is_running():asyncio.ensure_future(app.run_polling())else:app.run_polling()except Exception:app.run_polling()
bot.py+14-2