K00B404 commited on
Commit
ab7a840
1 Parent(s): 8aae98f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -9,7 +9,6 @@ from deep_translator import GoogleTranslator
9
  import json
10
 
11
  # Project by Nymbo
12
- #API_URL="https://huggingface.co/spaces/multimodalart/FLUX.1-merged"
13
  API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
14
  #API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
15
  API_TOKEN = os.getenv("HF_READ_TOKEN")
@@ -17,7 +16,7 @@ headers = {"Authorization": f"Bearer {API_TOKEN}"}
17
  timeout = 100
18
 
19
  def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
20
- if prompt == "" or prompt == None:
21
  return None
22
 
23
  key = random.randint(0, 999)
@@ -31,12 +30,16 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
31
  prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
32
  print(f'\033[1mGeneration {key}:\033[0m {prompt}')
33
 
 
 
 
 
34
  payload = {
35
  "inputs": prompt,
36
  "is_negative": is_negative,
37
  "steps": steps,
38
  "cfg_scale": cfg_scale,
39
- "seed": seed if seed != -1 else random.randint(1, 1000000000),
40
  "strength": strength
41
  }
42
 
@@ -52,7 +55,8 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
52
  image_bytes = response.content
53
  image = Image.open(io.BytesIO(image_bytes))
54
  print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
55
- return image
 
56
  except Exception as e:
57
  print(f"Error when trying to open the image: {e}")
58
  return None
 
9
  import json
10
 
11
  # Project by Nymbo
 
12
  API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
13
  #API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
14
  API_TOKEN = os.getenv("HF_READ_TOKEN")
 
16
  timeout = 100
17
 
18
  def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
19
+ if prompt == "" or prompt is None:
20
  return None
21
 
22
  key = random.randint(0, 999)
 
30
  prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
31
  print(f'\033[1mGeneration {key}:\033[0m {prompt}')
32
 
33
+ # If seed is -1, generate a random seed and use it
34
+ if seed == -1:
35
+ seed = random.randint(1, 1000000000)
36
+
37
  payload = {
38
  "inputs": prompt,
39
  "is_negative": is_negative,
40
  "steps": steps,
41
  "cfg_scale": cfg_scale,
42
+ "seed": seed,
43
  "strength": strength
44
  }
45
 
 
55
  image_bytes = response.content
56
  image = Image.open(io.BytesIO(image_bytes))
57
  print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
58
+ # Return both the image and the seed used
59
+ return image, seed
60
  except Exception as e:
61
  print(f"Error when trying to open the image: {e}")
62
  return None