Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,25 @@
|
|
| 1 |
import os
|
|
|
|
|
|
|
| 2 |
import requests
|
| 3 |
import discord
|
| 4 |
from discord import app_commands
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
|
|
@@ -33,8 +50,7 @@ def ask_llm(prompt: str) -> str:
|
|
| 33 |
if r.status_code != 200:
|
| 34 |
return "❌ LLM не ответил"
|
| 35 |
|
| 36 |
-
|
| 37 |
-
return data[0]["generated_text"]
|
| 38 |
|
| 39 |
|
| 40 |
@tree.command(name="experiment", description="Философский эксперимент")
|
|
|
|
| 1 |
import os
|
| 2 |
+
import time
|
| 3 |
+
import socket
|
| 4 |
import requests
|
| 5 |
import discord
|
| 6 |
from discord import app_commands
|
| 7 |
|
| 8 |
+
def wait_for_internet(host="discord.com", port=443, timeout=60):
|
| 9 |
+
start = time.time()
|
| 10 |
+
while True:
|
| 11 |
+
try:
|
| 12 |
+
socket.getaddrinfo(host, port)
|
| 13 |
+
print("🌐 Internet ready")
|
| 14 |
+
return
|
| 15 |
+
except socket.gaierror:
|
| 16 |
+
if time.time() - start > timeout:
|
| 17 |
+
raise RuntimeError("❌ Internet not available")
|
| 18 |
+
print("⏳ Waiting for internet...")
|
| 19 |
+
time.sleep(5)
|
| 20 |
+
|
| 21 |
+
wait_for_internet()
|
| 22 |
+
|
| 23 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
| 24 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 25 |
|
|
|
|
| 50 |
if r.status_code != 200:
|
| 51 |
return "❌ LLM не ответил"
|
| 52 |
|
| 53 |
+
return r.json()[0]["generated_text"]
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
@tree.command(name="experiment", description="Философский эксперимент")
|