Spaces:
Runtime error
Runtime error
Commit
•
81ab75e
1
Parent(s):
367f67e
Update app.py
Browse files
app.py
CHANGED
@@ -51,44 +51,39 @@ def elapsed_time(fn, *args):
|
|
51 |
return elapsed, output
|
52 |
|
53 |
|
54 |
-
|
|
|
55 |
|
56 |
-
|
57 |
-
st.write(f"Stable diffusion model is fine-tuned by lora using dataset {DATASET_REPO}")
|
58 |
|
59 |
-
|
|
|
|
|
60 |
|
61 |
-
|
62 |
-
elapsed, pipeline = elapsed_time(load_pipeline_w_lora)
|
63 |
-
st.write(f"Model is loaded in {elapsed} seconds!")
|
64 |
-
|
65 |
-
pipeline = pipeline.to(device)
|
66 |
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
num_images = st.number_input(label="Number of images to generate", min_value=1, max_value=10)
|
75 |
-
|
76 |
-
seed = st.number_input(label="Seed for images", min_value=1, max_value=10000)
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
if submitted :
|
81 |
-
st.write(f"Generating {num_images} BAYC image with prompt <{prompt}>...")
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
88 |
|
89 |
-
|
|
|
|
|
|
|
|
|
90 |
|
91 |
-
|
92 |
|
93 |
-
|
94 |
-
main()
|
|
|
51 |
return elapsed, output
|
52 |
|
53 |
|
54 |
+
st.title("BAYC Text to IMAGE generator")
|
55 |
+
st.write(f"Stable diffusion model is fine-tuned by lora using dataset {DATASET_REPO}")
|
56 |
|
57 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
|
|
58 |
|
59 |
+
st.write("Loading models...")
|
60 |
+
elapsed, pipeline = elapsed_time(load_pipeline_w_lora)
|
61 |
+
st.write(f"Model is loaded in {elapsed} seconds!")
|
62 |
|
63 |
+
pipeline = pipeline.to(device)
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
sample = Image.open(SAMPLE_IMAGE)
|
66 |
+
st.image(sample, caption="Example image with prompt <An ape with solid gold fur and beanie>")
|
67 |
|
68 |
+
with st.form(key="information", clear_on_submit=True):
|
69 |
+
prompt = st.text_input(
|
70 |
+
label="Write prompt to generate your unique BAYC image! (e.g. An ape with golden fur)")
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
num_images = st.number_input(label="Number of images to generate", min_value=1, max_value=10)
|
|
|
|
|
|
|
73 |
|
74 |
+
seed = st.number_input(label="Seed for images", min_value=1, max_value=10000)
|
75 |
+
|
76 |
+
submitted = st.form_submit_button(label="Submit")
|
77 |
+
|
78 |
+
if submitted :
|
79 |
+
st.write(f"Generating {num_images} BAYC image with prompt <{prompt}>...")
|
80 |
|
81 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
82 |
+
images = []
|
83 |
+
for img_idx in stqdm(range(num_images)):
|
84 |
+
generated_image = pipeline(prompt, num_inference_steps=30, generator=generator).images[0]
|
85 |
+
images.append(generated_image)
|
86 |
|
87 |
+
st.write("Done!")
|
88 |
|
89 |
+
st.image(images, width=150, caption=f"Generated Images with <{prompt}>")
|
|