Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
-
from diffusers import DiffusionPipeline
|
| 5 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
|
|
@@ -37,11 +39,10 @@ def infer(prompt_part1, color, dress_type, design, prompt_part5, negative_prompt
|
|
| 37 |
generator=generator
|
| 38 |
).images[0]
|
| 39 |
print("Image generated successfully.") # Debug: Confirm image generation
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
print(f"Error generating image: {e}")
|
| 42 |
return None
|
| 43 |
-
|
| 44 |
-
return image
|
| 45 |
|
| 46 |
examples = [
|
| 47 |
["red", "t-shirt", "yellow stripes"],
|
|
@@ -88,10 +89,23 @@ with gr.Blocks(css=css) as demo:
|
|
| 88 |
|
| 89 |
gr.Examples(examples=examples, inputs=[prompt_part2, prompt_part3, prompt_part4])
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
demo.queue().launch()
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import random
|
|
|
|
| 3 |
import torch
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from diffusers import DiffusionPipeline
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import io
|
| 8 |
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
|
|
|
|
| 39 |
generator=generator
|
| 40 |
).images[0]
|
| 41 |
print("Image generated successfully.") # Debug: Confirm image generation
|
| 42 |
+
return image
|
| 43 |
except Exception as e:
|
| 44 |
print(f"Error generating image: {e}")
|
| 45 |
return None
|
|
|
|
|
|
|
| 46 |
|
| 47 |
examples = [
|
| 48 |
["red", "t-shirt", "yellow stripes"],
|
|
|
|
| 89 |
|
| 90 |
gr.Examples(examples=examples, inputs=[prompt_part2, prompt_part3, prompt_part4])
|
| 91 |
|
| 92 |
+
def run_infer():
|
| 93 |
+
output_image = infer(
|
| 94 |
+
prompt_part1.value,
|
| 95 |
+
prompt_part2.value,
|
| 96 |
+
prompt_part3.value,
|
| 97 |
+
prompt_part4.value,
|
| 98 |
+
prompt_part5.value,
|
| 99 |
+
negative_prompt.value,
|
| 100 |
+
seed.value,
|
| 101 |
+
randomize_seed.value,
|
| 102 |
+
width.value,
|
| 103 |
+
height.value,
|
| 104 |
+
guidance_scale.value,
|
| 105 |
+
num_inference_steps.value
|
| 106 |
+
)
|
| 107 |
+
return output_image
|
| 108 |
+
|
| 109 |
+
run_button.click(fn=run_infer, outputs=result)
|
| 110 |
|
| 111 |
+
demo.queue(api_name="/infer").launch()
|