Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,17 +5,12 @@ from PIL import Image
|
|
5 |
import os
|
6 |
# HARDCODED_URL = "" # Replace with your desired URL
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
no_of_accounts = 3
|
13 |
-
|
14 |
-
import gradio as gr
|
15 |
-
from PIL import Image
|
16 |
-
from io import BytesIO
|
17 |
-
import requests
|
18 |
-
import os
|
19 |
|
20 |
def get_image_from_url(url):
|
21 |
"""
|
@@ -32,27 +27,27 @@ def get_image_from_url(url):
|
|
32 |
return f"Error processing image: {e}"
|
33 |
|
34 |
def generate_image(prompt, aspect_ratio, realism):
|
35 |
-
global
|
36 |
-
global
|
37 |
-
global
|
38 |
global no_of_accounts
|
39 |
|
40 |
payload = {
|
41 |
-
"id":
|
42 |
"inputs": [prompt, aspect_ratio, str(realism).lower()],
|
43 |
}
|
44 |
-
headers = {"Authorization": f"Bearer {
|
45 |
|
46 |
try:
|
47 |
-
response_data = requests.post(
|
48 |
if "error" in response_data:
|
49 |
if 'error 429' in response_data['error']:
|
50 |
-
if
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
response_data = generate_image(prompt, aspect_ratio, realism)
|
55 |
-
|
56 |
return response_data
|
57 |
return "No credits available"
|
58 |
return response_data
|
@@ -62,7 +57,7 @@ def generate_image(prompt, aspect_ratio, realism):
|
|
62 |
else:
|
63 |
return "Error: Unexpected response from server"
|
64 |
except Exception as e:
|
65 |
-
return f"Error
|
66 |
|
67 |
# Define the Gradio interface
|
68 |
interface = gr.Interface(
|
|
|
5 |
import os
|
6 |
# HARDCODED_URL = "" # Replace with your desired URL
|
7 |
|
8 |
+
TOKEN = os.getenv("TOKEN1")
|
9 |
+
API_URL = os.getenv("API_URL")
|
10 |
+
token_id = 1
|
11 |
+
tokens_tried = 0
|
12 |
no_of_accounts = 3
|
13 |
+
model_id = os.getenv("cm3ugmzv2002gnckiosrwk6xi")
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def get_image_from_url(url):
|
16 |
"""
|
|
|
27 |
return f"Error processing image: {e}"
|
28 |
|
29 |
def generate_image(prompt, aspect_ratio, realism):
|
30 |
+
global token_id
|
31 |
+
global TOKEN
|
32 |
+
global tokens_tried
|
33 |
global no_of_accounts
|
34 |
|
35 |
payload = {
|
36 |
+
"id": model_id, # Replace with appropriate ID if necessary
|
37 |
"inputs": [prompt, aspect_ratio, str(realism).lower()],
|
38 |
}
|
39 |
+
headers = {"Authorization": f"Bearer {TOKEN}"}
|
40 |
|
41 |
try:
|
42 |
+
response_data = requests.post(API_URL, json=payload, headers=headers).json()
|
43 |
if "error" in response_data:
|
44 |
if 'error 429' in response_data['error']:
|
45 |
+
if tokens_tried < no_of_accounts:
|
46 |
+
token_id = (token_id + 1) % no_of_accounts
|
47 |
+
tokens_tried += 1
|
48 |
+
TOKEN = os.getenv(f"TOKEN{token_id}")
|
49 |
response_data = generate_image(prompt, aspect_ratio, realism)
|
50 |
+
tokens_tried = 0
|
51 |
return response_data
|
52 |
return "No credits available"
|
53 |
return response_data
|
|
|
57 |
else:
|
58 |
return "Error: Unexpected response from server"
|
59 |
except Exception as e:
|
60 |
+
return f"Error"
|
61 |
|
62 |
# Define the Gradio interface
|
63 |
interface = gr.Interface(
|