ameerazam08 commited on
Commit
0541a7c
1 Parent(s): 134c931

app.py file

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import spaces
3
+ from diffusers import StableDiffusionPipeline, AutoencoderKL
4
+ import os
5
+ import torch
6
+ from PIL import Image
7
+ import random
8
+
9
+ # SAFETY_CHECKER = os.environ.get("SAFETY_CHECKER", "0") == "1"
10
+
11
+ # Constants
12
+ repo = "IDKiro/sdxs-512-0.9"
13
+
14
+
15
+ # Ensure model and scheduler are initialized in GPU-enabled function
16
+ if torch.cuda.is_available():
17
+ weight_type = torch.float32
18
+ pipe = StableDiffusionPipeline.from_pretrained(repo, torch_dtype=weight_type)
19
+
20
+ # pipe.vae = AutoencoderKL.from_pretrained("IDKiro/sdxs-512-0.9/vae_large") # use original VAE
21
+ pipe.to("cuda")
22
+
23
+ # Function
24
+ @spaces.GPU(enable_queue=True)
25
+ def generate_image(prompt):
26
+ seed = random.randint(-100000,100000)
27
+
28
+ results = pipe(
29
+ prompt,
30
+ num_inference_steps=1,
31
+ guidance_scale=0,
32
+ generator=torch.Generator(device="cuda").manual_seed(seed)
33
+ )
34
+ return results.images[0]
35
+
36
+
37
+
38
+ # Gradio Interface
39
+ description = """
40
+ This demo utilizes the SDXLS model
41
+ """
42
+
43
+ with gr.Blocks(css="style.css") as demo:
44
+ gr.HTML("<h1><center>Text-to-Image with SDXS ⚡</center></h1>")
45
+ gr.Markdown(description)
46
+ with gr.Group():
47
+ with gr.Row():
48
+ prompt = gr.Textbox(label='Enter your prompt (English)', scale=8, value="portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour")
49
+ num_inference_steps = gr.Slider(label="num_inference_steps", value=1,interactive=True)
50
+ submit = gr.Button(scale=1, variant='primary')
51
+ img = gr.Image(label='SDXS Generated Image')
52
+
53
+ prompt.submit(fn=generate_image,
54
+ inputs=[prompt],
55
+ outputs=img,
56
+ )
57
+ submit.click(fn=generate_image,
58
+ inputs=[prompt],
59
+ outputs=img,
60
+ )
61
+
62
+ demo.queue().launch()