Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -132,162 +132,6 @@ with gr.Blocks(theme=theme, fill_width=True, css=css) as app:
|
|
132 |
- **film-noir**: in the style of FLMNR
|
133 |
- **flux-lora-pro-headshot**: PROHEADSHOT
|
134 |
""")
|
135 |
-
with gr.Row():
|
136 |
-
custom_lora =
|
137 |
-
FLUX.Dev-LORA
|
138 |
-
/ app.py
|
139 |
-
DigiP-AI's picture
|
140 |
-
DigiP-AI
|
141 |
-
Update app.py
|
142 |
-
9026664
|
143 |
-
verified
|
144 |
-
1 day ago
|
145 |
-
raw
|
146 |
-
history
|
147 |
-
blame
|
148 |
-
edit
|
149 |
-
delete
|
150 |
-
11.8 kB
|
151 |
-
#!/usr/bin/env python
|
152 |
-
import gradio as gr
|
153 |
-
import requests
|
154 |
-
import io
|
155 |
-
import random
|
156 |
-
import os
|
157 |
-
import time
|
158 |
-
import numpy as np
|
159 |
-
import subprocess
|
160 |
-
import torch
|
161 |
-
import json
|
162 |
-
import uuid
|
163 |
-
import spaces
|
164 |
-
from typing import Tuple
|
165 |
-
from transformers import AutoProcessor, AutoModelForCausalLM
|
166 |
-
from PIL import Image
|
167 |
-
from deep_translator import GoogleTranslator
|
168 |
-
from datetime import datetime
|
169 |
-
from theme import theme
|
170 |
-
from typing import Tuple
|
171 |
-
from fastapi import FastAPI
|
172 |
-
|
173 |
-
app = FastAPI()
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
API_TOKEN = os.getenv("HF_READ_TOKEN")
|
178 |
-
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
179 |
-
timeout = 100
|
180 |
-
|
181 |
-
def flip_image(x):
|
182 |
-
return np.fliplr(x)
|
183 |
-
|
184 |
-
def clear():
|
185 |
-
return None
|
186 |
-
|
187 |
-
def query(lora_id, prompt, is_negative=False, steps=28, cfg_scale=3.5, sampler="DPM++ 2M Karras", seed=-1, strength=100, width=896, height=1152):
|
188 |
-
if prompt == "" or prompt == None:
|
189 |
-
return None
|
190 |
-
|
191 |
-
if lora_id.strip() == "" or lora_id == None:
|
192 |
-
lora_id = "black-forest-labs/FLUX.1-dev"
|
193 |
-
|
194 |
-
key = random.randint(0, 999)
|
195 |
-
|
196 |
-
API_URL = "https://api-inference.huggingface.co/models/"+ lora_id.strip()
|
197 |
-
|
198 |
-
API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN")])
|
199 |
-
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
200 |
-
|
201 |
-
# prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
202 |
-
# print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
|
203 |
-
prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
204 |
-
print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
|
205 |
-
|
206 |
-
prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
|
207 |
-
print(f'\033[1mGeneration {key}:\033[0m {prompt}')
|
208 |
-
|
209 |
-
# If seed is -1, generate a random seed and use it
|
210 |
-
if seed == -1:
|
211 |
-
seed = random.randint(1, 1000000000)
|
212 |
-
|
213 |
-
# Prepare the payload for the API call, including width and height
|
214 |
-
payload = {
|
215 |
-
"inputs": prompt,
|
216 |
-
"is_negative": is_negative,
|
217 |
-
"steps": steps,
|
218 |
-
"cfg_scale": cfg_scale,
|
219 |
-
"seed": seed if seed != -1 else random.randint(1, 1000000000),
|
220 |
-
"strength": strength,
|
221 |
-
"parameters": {
|
222 |
-
"width": width, # Pass the width to the API
|
223 |
-
"height": height # Pass the height to the API
|
224 |
-
}
|
225 |
-
}
|
226 |
-
|
227 |
-
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
228 |
-
if response.status_code != 200:
|
229 |
-
print(f"Error: Failed to get image. Response status: {response.status_code}")
|
230 |
-
print(f"Response content: {response.text}")
|
231 |
-
if response.status_code == 503:
|
232 |
-
raise gr.Error(f"{response.status_code} : The model is being loaded")
|
233 |
-
raise gr.Error(f"{response.status_code}")
|
234 |
-
|
235 |
-
try:
|
236 |
-
image_bytes = response.content
|
237 |
-
image = Image.open(io.BytesIO(image_bytes))
|
238 |
-
print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
|
239 |
-
return image, seed
|
240 |
-
except Exception as e:
|
241 |
-
print(f"Error when trying to open the image: {e}")
|
242 |
-
return None
|
243 |
-
|
244 |
-
examples = [
|
245 |
-
"a beautiful woman with blonde hair and blue eyes",
|
246 |
-
"a beautiful woman with brown hair and grey eyes",
|
247 |
-
"a beautiful woman with black hair and brown eyes",
|
248 |
-
]
|
249 |
-
|
250 |
-
css = """
|
251 |
-
#app-container {
|
252 |
-
max-width: 930px;
|
253 |
-
margin-left: auto;
|
254 |
-
margin-right: auto;
|
255 |
-
}
|
256 |
-
".gradio-container {background: url('file=abstract.jpg')}
|
257 |
-
|
258 |
-
"""
|
259 |
-
with gr.Blocks(theme=theme, css=css, elem_id="app-container") as app:
|
260 |
-
gr.HTML("<center><h6>🎨 FLUX.1-Dev with LoRA 🇬🇧</h6></center>")
|
261 |
-
with gr.Tab("Text to Image"):
|
262 |
-
with gr.Column(elem_id="app-container"):
|
263 |
-
with gr.Row():
|
264 |
-
with gr.Column(elem_id="prompt-container"):
|
265 |
-
with gr.Group():
|
266 |
-
with gr.Row():
|
267 |
-
text_prompt = gr.Textbox(label="Image Prompt ✍️", placeholder="Enter a prompt here", lines=2, show_copy_button = True, elem_id="prompt-text-input")
|
268 |
-
with gr.Row():
|
269 |
-
with gr.Accordion("🎨 Lora trigger words", open=False):
|
270 |
-
gr.Markdown("""
|
271 |
-
- **Canopus-Pencil-Art-LoRA**: Pencil Art
|
272 |
-
- **Flux-Realism-FineDetailed**: Fine Detailed
|
273 |
-
- **Fashion-Hut-Modeling-LoRA**: Modeling
|
274 |
-
- **SD3.5-Large-Turbo-HyperRealistic-LoRA**: hyper realistic
|
275 |
-
- **Flux-Fine-Detail-LoRA**: Super Detail
|
276 |
-
- **SD3.5-Turbo-Realism-2.0-LoRA**: Turbo Realism
|
277 |
-
- **Canopus-LoRA-Flux-UltraRealism-2.0**: Ultra realistic
|
278 |
-
- **Canopus-Pencil-Art-LoRA**: Pencil Art
|
279 |
-
- **SD3.5-Large-Photorealistic-LoRA**: photorealistic
|
280 |
-
- **Flux.1-Dev-LoRA-HDR-Realism**: HDR
|
281 |
-
- **prithivMLmods/Ton618-Epic-Realism-Flux-LoRA**: Epic Realism
|
282 |
-
- **john-singer-sargent-style**: John Singer Sargent Style
|
283 |
-
- **alphonse-mucha-style**: Alphonse Mucha Style
|
284 |
-
- **ultra-realistic-illustration**: ultra realistic illustration
|
285 |
-
- **eye-catching**: eye-catching
|
286 |
-
- **john-constable-style**: John Constable Style
|
287 |
-
- **film-noir**: in the style of FLMNR
|
288 |
-
- **flux-lora-pro-headshot**: PROHEADSHOT
|
289 |
-
""")
|
290 |
-
|
291 |
with gr.Row():
|
292 |
custom_lora = gr.Dropdown([" ", "prithivMLmods/Canopus-Pencil-Art-LoRA", "prithivMLmods/Flux-Realism-FineDetailed", "prithivMLmods/Fashion-Hut-Modeling-LoRA", "prithivMLmods/SD3.5-Large-Turbo-HyperRealistic-LoRA", "prithivMLmods/Flux-Fine-Detail-LoRA", "prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA", "hugovntr/flux-schnell-realism", "fofr/sdxl-deep-down", "prithivMLmods/Canopus-LoRA-Flux-UltraRealism-2.0", "prithivMLmods/Canopus-Realism-LoRA", "prithivMLmods/Canopus-LoRA-Flux-FaceRealism", "prithivMLmods/SD3.5-Large-Photorealistic-LoRA", "prithivMLmods/Flux.1-Dev-LoRA-HDR-Realism", "prithivMLmods/Ton618-Epic-Realism-Flux-LoRA", "KappaNeuro/john-singer-sargent-style", "KappaNeuro/alphonse-mucha-style", "ntc-ai/SDXL-LoRA-slider.ultra-realistic-illustration", "ntc-ai/SDXL-LoRA-slider.eye-catching", "KappaNeuro/john-constable-style", "dvyio/flux-lora-film-noir", "dvyio/flux-lora-pro-headshot"], label="Custom LoRA",)
|
293 |
with gr.Accordion("Advanced options", open=False):
|
|
|
132 |
- **film-noir**: in the style of FLMNR
|
133 |
- **flux-lora-pro-headshot**: PROHEADSHOT
|
134 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
with gr.Row():
|
136 |
custom_lora = gr.Dropdown([" ", "prithivMLmods/Canopus-Pencil-Art-LoRA", "prithivMLmods/Flux-Realism-FineDetailed", "prithivMLmods/Fashion-Hut-Modeling-LoRA", "prithivMLmods/SD3.5-Large-Turbo-HyperRealistic-LoRA", "prithivMLmods/Flux-Fine-Detail-LoRA", "prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA", "hugovntr/flux-schnell-realism", "fofr/sdxl-deep-down", "prithivMLmods/Canopus-LoRA-Flux-UltraRealism-2.0", "prithivMLmods/Canopus-Realism-LoRA", "prithivMLmods/Canopus-LoRA-Flux-FaceRealism", "prithivMLmods/SD3.5-Large-Photorealistic-LoRA", "prithivMLmods/Flux.1-Dev-LoRA-HDR-Realism", "prithivMLmods/Ton618-Epic-Realism-Flux-LoRA", "KappaNeuro/john-singer-sargent-style", "KappaNeuro/alphonse-mucha-style", "ntc-ai/SDXL-LoRA-slider.ultra-realistic-illustration", "ntc-ai/SDXL-LoRA-slider.eye-catching", "KappaNeuro/john-constable-style", "dvyio/flux-lora-film-noir", "dvyio/flux-lora-pro-headshot"], label="Custom LoRA",)
|
137 |
with gr.Accordion("Advanced options", open=False):
|