Spaces:
No application file
No application file
Commit
•
1b2d0b3
1
Parent(s):
7817f3d
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,38 @@
|
|
1 |
-
|
|
|
|
|
2 |
import gradio as gr
|
3 |
-
from diffusers import StableDiffusionPipeline
|
|
|
4 |
|
5 |
class CFG:
|
6 |
-
device =
|
7 |
seed = 42
|
8 |
-
|
9 |
-
image_gen_steps = 35
|
10 |
-
image_gen_model_id =
|
11 |
image_gen_size = (400, 400)
|
12 |
image_gen_guidance_scale = 9
|
13 |
|
14 |
image_gen_model = StableDiffusionPipeline.from_pretrained(
|
15 |
CFG.image_gen_model_id, torch_dtype=torch.float32,
|
16 |
-
revision="fp16", use_auth_token='hf_pxvzpoafqjfkELFKMLTESNpvmyvkTVuD01'
|
17 |
)
|
18 |
-
|
19 |
apply = image_gen_model.to(CFG.device)
|
20 |
|
21 |
def generate_image(prompt):
|
|
|
22 |
image = apply(
|
23 |
prompt, num_inference_steps=CFG.image_gen_steps,
|
24 |
-
generator=CFG.generator
|
25 |
guidance_scale=CFG.image_gen_guidance_scale
|
26 |
-
).
|
27 |
image = image.resize(CFG.image_gen_size)
|
28 |
return image
|
29 |
-
|
30 |
|
31 |
|
32 |
-
title = "
|
33 |
-
description = "
|
34 |
|
35 |
-
iface = gr.
|
36 |
-
iface.launch(
|
37 |
-
)
|
|
|
1 |
+
### App
|
2 |
+
### This code for app.py
|
3 |
+
import torch
|
4 |
import gradio as gr
|
5 |
+
from diffusers import StableDiffusionPipeline
|
6 |
+
|
7 |
|
8 |
class CFG:
|
9 |
+
device = "cpu"
|
10 |
seed = 42
|
11 |
+
generator = torch.Generator(device).manual_seed(seed)
|
12 |
+
image_gen_steps = 35
|
13 |
+
image_gen_model_id = "stabilityai/stable-diffusion-2"
|
14 |
image_gen_size = (400, 400)
|
15 |
image_gen_guidance_scale = 9
|
16 |
|
17 |
image_gen_model = StableDiffusionPipeline.from_pretrained(
|
18 |
CFG.image_gen_model_id, torch_dtype=torch.float32,
|
19 |
+
revision="fp16", use_auth_token='hf_pxvzpoafqjfkELFKMLTESNpvmyvkTVuD01', guidance_scale=9
|
20 |
)
|
|
|
21 |
apply = image_gen_model.to(CFG.device)
|
22 |
|
23 |
def generate_image(prompt):
|
24 |
+
## add translation model here before apply
|
25 |
image = apply(
|
26 |
prompt, num_inference_steps=CFG.image_gen_steps,
|
27 |
+
generator=CFG.generator,
|
28 |
guidance_scale=CFG.image_gen_guidance_scale
|
29 |
+
).images[0]
|
30 |
image = image.resize(CFG.image_gen_size)
|
31 |
return image
|
|
|
32 |
|
33 |
|
34 |
+
title = "نموذج توليد الصور"
|
35 |
+
description = " اكتب وصف للصورة التي تود من النظام التوليدي انشاءها"
|
36 |
|
37 |
+
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image", title=title, description=description)
|
38 |
+
iface.launch()
|
|