Sebastiankay commited on
Commit
cc85e57
1 Parent(s): 1405ad0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -12
app.py CHANGED
@@ -1,25 +1,39 @@
1
- import os, sys, json, re, time, base64, random, requests, shutil
2
  import gradio as gr
 
 
 
 
 
3
  from datetime import datetime
4
  import urllib.parse
5
  from groq import Groq
6
  from exif import Image
7
  from PIL import Image as PILImage, ExifTags as PILExifTags
 
8
  import colorsys
9
 
10
  # MARK: INIT
11
- MAX_SEED = 9999
12
  MAX_IMAGE_SIZE = 2048
13
 
14
- GROQ_APIKEY_PROMPTENHANCE = os.environ["GROQ_APIKEY_PROMPTENHANCE"]
 
 
 
 
 
 
 
 
15
 
16
- # delete cache folder if exist and create new
17
  CACHE_DIR = os.path.join(os.path.dirname(__file__), "cache")
18
  IMAGE_DIR = os.path.join(CACHE_DIR, "images")
19
- if os.path.exists(CACHE_DIR):
20
- shutil.rmtree(CACHE_DIR)
21
- os.makedirs(CACHE_DIR)
22
- os.makedirs(IMAGE_DIR)
 
23
 
24
  RES = os.path.join(os.path.dirname(__file__), "_res")
25
 
@@ -227,18 +241,18 @@ with gr.Blocks(theme=theme, head=custom_head, css=custom_css, js=custom_js, titl
227
  def calculate_ratio_values(image_ratio_buttons, image_width, image_height):
228
  ratio_value = image_ratio_buttons.split(":")
229
  if int(ratio_value[0]) > int(ratio_value[1]):
230
- a = 1024
231
  b = int(a * int(ratio_value[1]) / int(ratio_value[0]))
232
  new_width = a
233
  new_height = b
234
  elif int(ratio_value[0]) < int(ratio_value[1]):
235
- b = 1024
236
  a = int(b * int(ratio_value[0]) / int(ratio_value[1]))
237
  new_width = a
238
  new_height = b
239
  else:
240
- new_width = 1024
241
- new_height = 1024
242
 
243
  return new_width, new_height
244
 
 
1
+ import os, sys, json, re, time, base64, random, shutil
2
  import gradio as gr
3
+ import numpy as np
4
+ import requests
5
+ from requests import Session
6
+ from requests.adapters import HTTPAdapter
7
+ from requests.packages.urllib3.util.retry import Retry
8
  from datetime import datetime
9
  import urllib.parse
10
  from groq import Groq
11
  from exif import Image
12
  from PIL import Image as PILImage, ExifTags as PILExifTags
13
+ from io import BytesIO
14
  import colorsys
15
 
16
  # MARK: INIT
17
+ MAX_SEED = np.iinfo(np.int32).max
18
  MAX_IMAGE_SIZE = 2048
19
 
20
+ GROQ_APIKEY_PROMPTENHANCE = os.getenv("GROQ_APIKEY_PROMPTENHANCE")
21
+ API_V1 = os.getenv("API_V1")
22
+ API_V1_MODELS = urllib.parse.unquote(API_V1 + "/models")
23
+ API_V1_IMAGE = urllib.parse.unquote(API_V1 + "/imagine2")
24
+ API_OLD = os.getenv("API_OLD")
25
+
26
+ # print(API_V1_MODELS)
27
+ # print(API_V1_IMAGE)
28
+
29
 
 
30
  CACHE_DIR = os.path.join(os.path.dirname(__file__), "cache")
31
  IMAGE_DIR = os.path.join(CACHE_DIR, "images")
32
+ if not os.path.exists(CACHE_DIR):
33
+ os.makedirs(CACHE_DIR)
34
+ print(f"Created cache dir on path {CACHE_DIR}")
35
+ os.makedirs(IMAGE_DIR)
36
+ print(f"Created images dir on path {IMAGE_DIR}")
37
 
38
  RES = os.path.join(os.path.dirname(__file__), "_res")
39
 
 
241
  def calculate_ratio_values(image_ratio_buttons, image_width, image_height):
242
  ratio_value = image_ratio_buttons.split(":")
243
  if int(ratio_value[0]) > int(ratio_value[1]):
244
+ a = 2048
245
  b = int(a * int(ratio_value[1]) / int(ratio_value[0]))
246
  new_width = a
247
  new_height = b
248
  elif int(ratio_value[0]) < int(ratio_value[1]):
249
+ b = 2048
250
  a = int(b * int(ratio_value[0]) / int(ratio_value[1]))
251
  new_width = a
252
  new_height = b
253
  else:
254
+ new_width = 2048
255
+ new_height = 2048
256
 
257
  return new_width, new_height
258