Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,9 @@ import gradio as gr # Import Gradio
|
|
10 |
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
|
11 |
GLIF_API_TOKEN = os.getenv("GLIF_API_TOKEN")
|
12 |
GLIF_API_URL = "https://simple-api.glif.app"
|
13 |
-
|
|
|
|
|
14 |
if not DISCORD_BOT_TOKEN or not GLIF_API_TOKEN:
|
15 |
raise ValueError("Both DISCORD_BOT_TOKEN and GLIF_API_TOKEN must be set.")
|
16 |
|
@@ -34,7 +36,14 @@ async def generate_image_async(prompt, aspect_ratio):
|
|
34 |
) as response:
|
35 |
response.raise_for_status()
|
36 |
response_data = await response.json()
|
37 |
-
if "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
return response_data
|
39 |
elif "error" in response_data:
|
40 |
return response_data['error']
|
|
|
10 |
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
|
11 |
GLIF_API_TOKEN = os.getenv("GLIF_API_TOKEN")
|
12 |
GLIF_API_URL = "https://simple-api.glif.app"
|
13 |
+
glif_token_id = 0
|
14 |
+
glif_tokens_tried = 0
|
15 |
+
no_of_accounts = 7
|
16 |
if not DISCORD_BOT_TOKEN or not GLIF_API_TOKEN:
|
17 |
raise ValueError("Both DISCORD_BOT_TOKEN and GLIF_API_TOKEN must be set.")
|
18 |
|
|
|
36 |
) as response:
|
37 |
response.raise_for_status()
|
38 |
response_data = await response.json()
|
39 |
+
if "error" in response_data:
|
40 |
+
if 'error 429' in response_data['error']:
|
41 |
+
if glif_tokens_tried<no_of_accounts:
|
42 |
+
global glif_token_id = (glif_token_id+1)%no_of_accounts
|
43 |
+
global GLIF_API_TOKEN = os.getenv(f"GLIF_API_TOKEN{glif_token_id}")
|
44 |
+
response_data = await generate_image_async(prompt, aspect_ratio)
|
45 |
+
glif_tokens_tried = 0
|
46 |
+
response_data = "No credits available"
|
47 |
return response_data
|
48 |
elif "error" in response_data:
|
49 |
return response_data['error']
|