Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,6 +23,7 @@ async def generate_image(prompt, model, lora_word, width, height, scales, steps,
|
|
23 |
if seed == -1:
|
24 |
seed = random.randint(0, MAX_SEED)
|
25 |
seed = int(seed)
|
|
|
26 |
text = str(Translator().translate(prompt, 'English')) + "," + lora_word
|
27 |
client = AsyncInferenceClient()
|
28 |
image = await client.text_to_image(prompt=text, height=height, width=width, guidance_scale=scales, num_inference_steps=steps, model=model)
|
@@ -44,7 +45,7 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
44 |
model = enable_lora(lora_model, basemodel) if process_lora else basemodel
|
45 |
image, seed = await generate_image(prompt, model, "", width, height, scales, steps, seed)
|
46 |
if image is None:
|
47 |
-
return [None, None]
|
48 |
|
49 |
image_path = "temp_image.jpg"
|
50 |
image.save(image_path, format="JPEG")
|
@@ -54,12 +55,12 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
54 |
if upscale_image_path is not None:
|
55 |
upscale_image = Image.open(upscale_image_path)
|
56 |
upscale_image.save("upscale_image.jpg", format="JPEG")
|
57 |
-
return [image_path, "upscale_image.jpg"]
|
58 |
else:
|
59 |
print("Error: The scaled image path is None")
|
60 |
-
return [image_path, image_path]
|
61 |
else:
|
62 |
-
return [image_path, image_path]
|
63 |
|
64 |
css = """
|
65 |
#col-container{ margin: 0 auto; max-width: 1024px;}
|
@@ -84,8 +85,8 @@ with gr.Blocks(css=css) as demo:
|
|
84 |
scales = gr.Slider(label="Scale", minimum=1, maximum=20, step=1, value=8)
|
85 |
steps = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=8)
|
86 |
seed = gr.Number(label="Seed", value=-1)
|
87 |
-
print(seed)
|
88 |
|
89 |
btn = gr.Button("Generate")
|
90 |
-
|
|
|
91 |
demo.launch()
|
|
|
23 |
if seed == -1:
|
24 |
seed = random.randint(0, MAX_SEED)
|
25 |
seed = int(seed)
|
26 |
+
print(f"Selected Seed: {seed}") # Print the seed
|
27 |
text = str(Translator().translate(prompt, 'English')) + "," + lora_word
|
28 |
client = AsyncInferenceClient()
|
29 |
image = await client.text_to_image(prompt=text, height=height, width=width, guidance_scale=scales, num_inference_steps=steps, model=model)
|
|
|
45 |
model = enable_lora(lora_model, basemodel) if process_lora else basemodel
|
46 |
image, seed = await generate_image(prompt, model, "", width, height, scales, steps, seed)
|
47 |
if image is None:
|
48 |
+
return [None, None, "Error: Failed to generate image"]
|
49 |
|
50 |
image_path = "temp_image.jpg"
|
51 |
image.save(image_path, format="JPEG")
|
|
|
55 |
if upscale_image_path is not None:
|
56 |
upscale_image = Image.open(upscale_image_path)
|
57 |
upscale_image.save("upscale_image.jpg", format="JPEG")
|
58 |
+
return [image_path, "upscale_image.jpg", seed]
|
59 |
else:
|
60 |
print("Error: The scaled image path is None")
|
61 |
+
return [image_path, image_path, seed]
|
62 |
else:
|
63 |
+
return [image_path, image_path, seed]
|
64 |
|
65 |
css = """
|
66 |
#col-container{ margin: 0 auto; max-width: 1024px;}
|
|
|
85 |
scales = gr.Slider(label="Scale", minimum=1, maximum=20, step=1, value=8)
|
86 |
steps = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=8)
|
87 |
seed = gr.Number(label="Seed", value=-1)
|
|
|
88 |
|
89 |
btn = gr.Button("Generate")
|
90 |
+
seed_output = gr.Textbox(label="Selected Seed") # Add output for seed
|
91 |
+
btn.click(fn=gen, inputs=[prompt, basemodel_choice, width, height, scales, steps, seed, upscale_factor, process_upscale, lora_model_choice, process_lora], outputs=[output_res, seed_output])
|
92 |
demo.launch()
|