Spaces:
Paused
Paused
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 3 |
+
β FRAGMENT SCANNER BOT β DEPLOYMENT GUIDE β
|
| 4 |
+
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
|
| 5 |
+
β β
|
| 6 |
+
β STEP 1 β Create Hugging Face Space β
|
| 7 |
+
β huggingface.co/new-space β
|
| 8 |
+
β SDK: Docker | Visibility: Private β
|
| 9 |
+
β β
|
| 10 |
+
β STEP 2 β Add Repository Secrets (Space β Settings β Secrets) β
|
| 11 |
+
β TELEGRAM_BOT_TOKEN your BotFather token β
|
| 12 |
+
β REDIS_URL full redis:// connection string β
|
| 13 |
+
β ADMIN_USER_IDS comma-separated Telegram user IDs β
|
| 14 |
+
β (get your ID from @userinfobot on Telegram) β
|
| 15 |
+
β β
|
| 16 |
+
β STEP 3 β Push code β
|
| 17 |
+
β git clone https://huggingface.co/spaces/YOU/SPACE β
|
| 18 |
+
β cp *.py Dockerfile requirements.txt ./SPACE/ β
|
| 19 |
+
β cd SPACE && git add . && git commit -m "deploy" && git push β
|
| 20 |
+
β Watch build in Space β Logs tab. β
|
| 21 |
+
β β
|
| 22 |
+
β STEP 4 β Verify keep-alive β
|
| 23 |
+
β https://YOU-SPACE.hf.space/health β
|
| 24 |
+
β Should return: {"status":"ok","redis":"connected",...} β
|
| 25 |
+
β β
|
| 26 |
+
β STEP 5 β UptimeRobot (prevents HF Space from sleeping) β
|
| 27 |
+
β uptimerobot.com β New Monitor β HTTP(s) β
|
| 28 |
+
β URL: https://YOU-SPACE.hf.space/ping β
|
| 29 |
+
β Interval: 5 minutes β
|
| 30 |
+
β β
|
| 31 |
+
β STEP 6 β Test β
|
| 32 |
+
β Send /start to your bot. Then /ping to verify Redis. β
|
| 33 |
+
β Then /scan to start your first scan. β
|
| 34 |
+
β β
|
| 35 |
+
β COMMON ERRORS β
|
| 36 |
+
β Space crashes instantly β missing env var or import error β
|
| 37 |
+
β check Logs tab β
|
| 38 |
+
β Bot not responding β ADMIN_USER_IDS wrong β
|
| 39 |
+
β verify with @userinfobot β
|
| 40 |
+
β Redis unreachable β check REDIS_URL secret, β
|
| 41 |
+
β use /ping to test live β
|
| 42 |
+
β Port 7080 not responding β keep_alive must use AppRunner, β
|
| 43 |
+
β not web.run_app() β
|
| 44 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
import asyncio
|
| 48 |
+
import nest_asyncio
|
| 49 |
+
nest_asyncio.apply()
|
| 50 |
+
|
| 51 |
+
from keep_alive import start_server
|
| 52 |
+
from bot import run_bot
|
| 53 |
+
|
| 54 |
+
async def main():
|
| 55 |
+
await asyncio.gather(
|
| 56 |
+
start_server(),
|
| 57 |
+
run_bot(),
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
asyncio.run(main())
|