treasuraid commited on
Commit
81ab75e
1 Parent(s): 367f67e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -31
app.py CHANGED
@@ -51,44 +51,39 @@ def elapsed_time(fn, *args):
51
  return elapsed, output
52
 
53
 
54
- def main():
 
55
 
56
- st.title("BAYC Text to IMAGE generator")
57
- st.write(f"Stable diffusion model is fine-tuned by lora using dataset {DATASET_REPO}")
58
 
59
- device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
 
 
60
 
61
- st.write("Loading models...")
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
- sample = Image.open(SAMPLE_IMAGE)
68
- st.image(sample, caption="Example image with prompt <An ape with solid gold fur and beanie>")
69
 
70
- with st.form(key="information", clear_on_submit=True):
71
- prompt = st.text_input(
72
- label="Write prompt to generate your unique BAYC image! (e.g. An ape with golden fur)")
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
- submitted = st.form_submit_button(label="Submit")
79
-
80
- if submitted :
81
- st.write(f"Generating {num_images} BAYC image with prompt <{prompt}>...")
82
 
83
- generator = torch.Generator(device=device).manual_seed(seed)
84
- images = []
85
- for img_idx in stqdm(range(num_images)):
86
- generated_image = pipeline(prompt, num_inference_steps=30, generator=generator).images[0]
87
- images.append(generated_image)
 
88
 
89
- st.write("Done!")
 
 
 
 
90
 
91
- st.image(images, width=150, caption=f"Generated Images with <{prompt}>")
92
 
93
- if __name__ == '__main__':
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}>")