Arnaviit commited on
Commit
d7b3554
·
verified ·
1 Parent(s): 5578848

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusion3Pipeline
4
+
5
+ def image_generation(prompt):
6
+ device = "cuda" if torch.cuda.is_available() else "cpu"
7
+ pipeline = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", torch_dtype = torch.float16 if device =="cuda" else torch.float32, text_encoder_3 = None, tokenizer_3 = None)
8
+
9
+ pipeline.enable_model_cpu_offload()
10
+ #pipeline.to(device)
11
+
12
+ image = pipeline(
13
+ prompt = prompt,
14
+ negative_prompt = "blurred,ugly,watermark, low resolution, blurry",
15
+ num_inference_steps= 50,
16
+ height = 1024,
17
+ width = 1024,
18
+ guidance_scale= 9.0,
19
+ ).images[0]
20
+
21
+ image.show()
22
+
23
+ #image_generation(" A Boy Standing Near the River Bank")
24
+
25
+ interface = gr.Interface(
26
+ fn=image_generation,
27
+ inputs=gr.Textbox(lines=2, placeholder="Enter your Prompt..."),
28
+ outputs=gr.Image(type="pil"),
29
+ title="AI Image Generator By Arnav Anand",
30
+ description="This application will be used to generate awesome images using SD3 model"
31
+ )
32
+
33
+ interface.launch()