DigiP-AI commited on
Commit
143ca85
·
verified ·
1 Parent(s): 3c9286b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -56,26 +56,29 @@ def query(lora_id, prompt, is_negative=False, steps=28, cfg_scale=3.5, sampler="
56
  return None
57
 
58
  if lora_id.strip() == "" or lora_id == None:
59
- lora_id = "black-forest-labs/FLUX.1-dev"
60
 
61
  key = random.randint(0, 999)
62
 
63
  API_URL = "https://api-inference.huggingface.co/models/"+ lora_id.strip()
64
-
65
  API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN")])
66
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
67
 
68
  # prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
69
  # print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
 
 
70
 
71
  prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
72
- # print(f'\033[1mGeneration {key}:\033[0m {prompt}')
73
 
74
  # If seed is -1, generate a random seed and use it
75
  if seed == -1:
76
  seed = random.randint(1, 1000000000)
77
-
78
- payload = {
 
79
  "inputs": prompt,
80
  "is_negative": is_negative,
81
  "steps": steps,
@@ -95,23 +98,23 @@ def query(lora_id, prompt, is_negative=False, steps=28, cfg_scale=3.5, sampler="
95
  if response.status_code == 503:
96
  raise gr.Error(f"{response.status_code} : The model is being loaded")
97
  raise gr.Error(f"{response.status_code}")
98
-
99
  try:
100
  image_bytes = response.content
101
  image = Image.open(io.BytesIO(image_bytes))
102
  print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
103
- return image, seed, seed
104
  except Exception as e:
105
  print(f"Error when trying to open the image: {e}")
106
  return None
107
 
108
-
109
  examples = [
110
  "a beautiful woman with blonde hair and blue eyes",
111
  "a beautiful woman with brown hair and grey eyes",
112
  "a beautiful woman with black hair and brown eyes",
113
  ]
114
 
 
115
  css = """
116
  #app-container {
117
  max-width: 896px;
@@ -176,14 +179,13 @@ with gr.Blocks(theme=theme, css=css, elem_id="app-container") as app:
176
 
177
  with gr.Row():
178
  image_output = gr.Image(type="pil", label="Image Output", format="png", elem_id="gallery")
179
-
180
- gr.Examples(
181
- examples = examples,
182
- inputs = [text_prompt],
183
- )
184
-
185
-
186
- text_button.click(query, inputs=[custom_lora, text_prompt, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=[image_output, seed_output])
187
 
188
 
189
  app.launch(show_api=False, share=False)
 
56
  return None
57
 
58
  if lora_id.strip() == "" or lora_id == None:
59
+ lora_id = "black-forest-labs/FLUX.1-dev"
60
 
61
  key = random.randint(0, 999)
62
 
63
  API_URL = "https://api-inference.huggingface.co/models/"+ lora_id.strip()
64
+
65
  API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN")])
66
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
67
 
68
  # prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
69
  # print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
70
+ prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
71
+ print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
72
 
73
  prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
74
+ print(f'\033[1mGeneration {key}:\033[0m {prompt}')
75
 
76
  # If seed is -1, generate a random seed and use it
77
  if seed == -1:
78
  seed = random.randint(1, 1000000000)
79
+
80
+ # Prepare the payload for the API call, including width and height
81
+ payload = {
82
  "inputs": prompt,
83
  "is_negative": is_negative,
84
  "steps": steps,
 
98
  if response.status_code == 503:
99
  raise gr.Error(f"{response.status_code} : The model is being loaded")
100
  raise gr.Error(f"{response.status_code}")
101
+
102
  try:
103
  image_bytes = response.content
104
  image = Image.open(io.BytesIO(image_bytes))
105
  print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
106
+ return image, seed
107
  except Exception as e:
108
  print(f"Error when trying to open the image: {e}")
109
  return None
110
 
 
111
  examples = [
112
  "a beautiful woman with blonde hair and blue eyes",
113
  "a beautiful woman with brown hair and grey eyes",
114
  "a beautiful woman with black hair and brown eyes",
115
  ]
116
 
117
+
118
  css = """
119
  #app-container {
120
  max-width: 896px;
 
179
 
180
  with gr.Row():
181
  image_output = gr.Image(type="pil", label="Image Output", format="png", elem_id="gallery")
182
+
183
+ gr.Examples(
184
+ examples = examples,
185
+ inputs = [text_prompt],
186
+ )
187
+
188
+ text_button.click(query, inputs=[custom_lora, text_prompt, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=[image_output, seed_output])
 
189
 
190
 
191
  app.launch(show_api=False, share=False)