Spaces:
Runtime error
Runtime error
kasper-boy
commited on
Commit
•
d79bce7
1
Parent(s):
a4a6a0b
Update main.py
Browse files
main.py
CHANGED
@@ -1,32 +1,71 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from diffusers import
|
4 |
|
5 |
def image_generation(prompt):
|
6 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
7 |
-
pipeline =
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
#
|
12 |
pipeline.enable_model_cpu_offload()
|
13 |
-
|
14 |
image = pipeline(
|
15 |
-
prompt
|
16 |
-
negative_prompt
|
17 |
-
num_inference_steps
|
18 |
height=1024,
|
19 |
width=1024,
|
20 |
guidance_scale=8.0
|
21 |
).images[0]
|
22 |
|
23 |
-
image
|
24 |
|
25 |
-
interface= gr.
|
26 |
fn=image_generation,
|
27 |
-
inputs
|
28 |
-
outputs
|
29 |
-
title
|
30 |
)
|
31 |
|
32 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from diffusers import StableDiffusionPipeline
|
4 |
|
5 |
def image_generation(prompt):
|
6 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
7 |
+
pipeline = StableDiffusionPipeline.from_pretrained(
|
8 |
+
"stabilityai/stable-diffusion-3-medium",
|
9 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
10 |
+
)
|
11 |
+
#pipeline.to(device)
|
12 |
pipeline.enable_model_cpu_offload()
|
13 |
+
|
14 |
image = pipeline(
|
15 |
+
prompt=prompt,
|
16 |
+
negative_prompt="blurred, ugly, watermark, low resolution, blurry, nude",
|
17 |
+
num_inference_steps=40,
|
18 |
height=1024,
|
19 |
width=1024,
|
20 |
guidance_scale=8.0
|
21 |
).images[0]
|
22 |
|
23 |
+
return image
|
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 Text Generation By SD-3M"
|
30 |
)
|
31 |
|
32 |
+
interface.launch()
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
# import gradio as gr
|
41 |
+
# import torch
|
42 |
+
# from diffusers import StableDiffusers3Pipeline
|
43 |
+
|
44 |
+
# def image_generation(prompt):
|
45 |
+
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
46 |
+
# pipeline = StableDiffusers3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers",
|
47 |
+
# torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
48 |
+
# text_encoder_3 = None,
|
49 |
+
# tokenizer_3 = None)
|
50 |
+
# # pipeline.to(device)
|
51 |
+
# pipeline.enable_model_cpu_offload()
|
52 |
+
|
53 |
+
# image = pipeline(
|
54 |
+
# prompt = prompt,
|
55 |
+
# negative_prompt = "blurred, ugly, watermark, low resolution, blurry, nude",
|
56 |
+
# num_inference_steps = 40,
|
57 |
+
# height=1024,
|
58 |
+
# width=1024,
|
59 |
+
# guidance_scale=8.0
|
60 |
+
# ).images[0]
|
61 |
+
|
62 |
+
# image.show()
|
63 |
+
|
64 |
+
# interface= gr.interface(
|
65 |
+
# fn=image_generation,
|
66 |
+
# inputs = gr.Textbox(lines="2", placeholder="Enter Your Prompt ..."),
|
67 |
+
# outputs = gr.Image(type="pil"),
|
68 |
+
# title = "AI Text Generation By SD-3M"
|
69 |
+
# )
|
70 |
+
|
71 |
+
# interface.launch()
|