Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from discord.ext import commands
|
|
7 |
from dotenv import load_dotenv
|
8 |
import logging
|
9 |
import io
|
|
|
10 |
from PIL import Image
|
11 |
|
12 |
# Load environment variables from the .env file
|
@@ -23,14 +24,19 @@ logging.basicConfig(level=logging.INFO)
|
|
23 |
logger = logging.getLogger(__name__)
|
24 |
|
25 |
# Function to query the Hugging Face model with a structured prompt
|
26 |
-
def query(payload):
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
# Initialize the Discord bot with a default prefix
|
36 |
intents = discord.Intents.default()
|
@@ -97,3 +103,4 @@ async def help_custom(ctx):
|
|
97 |
# Run the bot
|
98 |
bot.run(DISCORD_TOKEN)
|
99 |
|
|
|
|
7 |
from dotenv import load_dotenv
|
8 |
import logging
|
9 |
import io
|
10 |
+
import time
|
11 |
from PIL import Image
|
12 |
|
13 |
# Load environment variables from the .env file
|
|
|
24 |
logger = logging.getLogger(__name__)
|
25 |
|
26 |
# Function to query the Hugging Face model with a structured prompt
|
27 |
+
def query(payload, max_retries=5, delay=5):
|
28 |
+
retries = 0
|
29 |
+
while retries < max_retries:
|
30 |
+
try:
|
31 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
32 |
+
response.raise_for_status()
|
33 |
+
return response.content
|
34 |
+
except requests.exceptions.RequestException as e:
|
35 |
+
logger.error(f"Error querying the API: {e}. Retrying in {delay} seconds...")
|
36 |
+
time.sleep(delay)
|
37 |
+
retries += 1
|
38 |
+
logger.error(f"Failed to query the API after {max_retries} attempts.")
|
39 |
+
return None
|
40 |
|
41 |
# Initialize the Discord bot with a default prefix
|
42 |
intents = discord.Intents.default()
|
|
|
103 |
# Run the bot
|
104 |
bot.run(DISCORD_TOKEN)
|
105 |
|
106 |
+
|