artintel235 commited on
Commit
d4bdcdb
·
verified ·
1 Parent(s): 9c51543

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -22
app.py CHANGED
@@ -5,17 +5,12 @@ from PIL import Image
5
  import os
6
  # HARDCODED_URL = "" # Replace with your desired URL
7
 
8
- GLIF_API_TOKEN = os.getenv("GLIF_API_TOKEN1")
9
- GLIF_API_URL = "https://simple-api.glif.app"
10
- glif_token_id = 1
11
- glif_tokens_tried = 0
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 glif_token_id
36
- global GLIF_API_TOKEN
37
- global glif_tokens_tried
38
  global no_of_accounts
39
 
40
  payload = {
41
- "id": "cm3ugmzv2002gnckiosrwk6xi", # Replace with appropriate ID if necessary
42
  "inputs": [prompt, aspect_ratio, str(realism).lower()],
43
  }
44
- headers = {"Authorization": f"Bearer {GLIF_API_TOKEN}"}
45
 
46
  try:
47
- response_data = requests.post(GLIF_API_URL, json=payload, headers=headers).json()
48
  if "error" in response_data:
49
  if 'error 429' in response_data['error']:
50
- if glif_tokens_tried < no_of_accounts:
51
- glif_token_id = (glif_token_id + 1) % no_of_accounts
52
- glif_tokens_tried += 1
53
- GLIF_API_TOKEN = os.getenv(f"GLIF_API_TOKEN{glif_token_id}")
54
  response_data = generate_image(prompt, aspect_ratio, realism)
55
- glif_tokens_tried = 0
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: {e}"
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(