Spaces:
Running
Running
salomonsky
commited on
Commit
•
c79e0ac
1
Parent(s):
043b00d
Update app.py
Browse files
app.py
CHANGED
@@ -16,14 +16,13 @@ llm_client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
16 |
def enable_lora(lora_add, basemodel):
|
17 |
return basemodel if not lora_add else lora_add
|
18 |
|
19 |
-
async def generate_image(
|
20 |
try:
|
21 |
if seed == -1:
|
22 |
seed = random.randint(0, MAX_SEED)
|
23 |
seed = int(seed)
|
24 |
-
text = prompt + "," + lora_word
|
25 |
image = await client.text_to_image(
|
26 |
-
prompt=
|
27 |
num_inference_steps=steps, model=model
|
28 |
)
|
29 |
return image, seed
|
@@ -40,7 +39,7 @@ def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
|
40 |
tile_height=144, denoise_strength=0.35, num_inference_steps=18,
|
41 |
solver="DDIM", api_name="/process"
|
42 |
)
|
43 |
-
return result[1]
|
44 |
except Exception as e:
|
45 |
return None
|
46 |
|
@@ -48,7 +47,12 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
48 |
model = enable_lora(lora_model, basemodel) if process_lora else basemodel
|
49 |
improved_prompt = await improve_prompt(prompt)
|
50 |
combined_prompt = f"{prompt} {improved_prompt}"
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
if isinstance(image, str) and image.startswith("Error"):
|
54 |
return [image, None]
|
@@ -58,7 +62,7 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
58 |
|
59 |
if process_upscale:
|
60 |
upscale_image_path = get_upscale_finegrain(combined_prompt, image_path, upscale_factor)
|
61 |
-
if upscale_image_path
|
62 |
upscale_image = Image.open(upscale_image_path)
|
63 |
upscale_image.save("upscale_image.jpg", format="JPEG")
|
64 |
return [image_path, "upscale_image.jpg"]
|
@@ -91,7 +95,7 @@ with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
|
91 |
prompt = gr.Textbox(label="Descripción de imágen")
|
92 |
basemodel_choice = gr.Dropdown(
|
93 |
label="Modelo",
|
94 |
-
choices=["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-DEV"
|
95 |
value="black-forest-labs/FLUX.1-schnell"
|
96 |
)
|
97 |
lora_model_choice = gr.Dropdown(
|
|
|
16 |
def enable_lora(lora_add, basemodel):
|
17 |
return basemodel if not lora_add else lora_add
|
18 |
|
19 |
+
async def generate_image(combined_prompt, model, width, height, scales, steps, seed):
|
20 |
try:
|
21 |
if seed == -1:
|
22 |
seed = random.randint(0, MAX_SEED)
|
23 |
seed = int(seed)
|
|
|
24 |
image = await client.text_to_image(
|
25 |
+
prompt=combined_prompt, height=height, width=width, guidance_scale=scales,
|
26 |
num_inference_steps=steps, model=model
|
27 |
)
|
28 |
return image, seed
|
|
|
39 |
tile_height=144, denoise_strength=0.35, num_inference_steps=18,
|
40 |
solver="DDIM", api_name="/process"
|
41 |
)
|
42 |
+
return result[1] if isinstance(result, list) and len(result) > 1 else None
|
43 |
except Exception as e:
|
44 |
return None
|
45 |
|
|
|
47 |
model = enable_lora(lora_model, basemodel) if process_lora else basemodel
|
48 |
improved_prompt = await improve_prompt(prompt)
|
49 |
combined_prompt = f"{prompt} {improved_prompt}"
|
50 |
+
|
51 |
+
if seed == -1:
|
52 |
+
seed = random.randint(0, MAX_SEED)
|
53 |
+
seed = int(seed)
|
54 |
+
|
55 |
+
image, seed = await generate_image(combined_prompt, model, width, height, scales, steps, seed)
|
56 |
|
57 |
if isinstance(image, str) and image.startswith("Error"):
|
58 |
return [image, None]
|
|
|
62 |
|
63 |
if process_upscale:
|
64 |
upscale_image_path = get_upscale_finegrain(combined_prompt, image_path, upscale_factor)
|
65 |
+
if upscale_image_path:
|
66 |
upscale_image = Image.open(upscale_image_path)
|
67 |
upscale_image.save("upscale_image.jpg", format="JPEG")
|
68 |
return [image_path, "upscale_image.jpg"]
|
|
|
95 |
prompt = gr.Textbox(label="Descripción de imágen")
|
96 |
basemodel_choice = gr.Dropdown(
|
97 |
label="Modelo",
|
98 |
+
choices=["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-DEV"],
|
99 |
value="black-forest-labs/FLUX.1-schnell"
|
100 |
)
|
101 |
lora_model_choice = gr.Dropdown(
|