salehalmansour commited on
Commit
1b2d0b3
1 Parent(s): 7817f3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -1,37 +1,38 @@
1
- import torch
 
 
2
  import gradio as gr
3
- from diffusers import StableDiffusionPipeline
 
4
 
5
  class CFG:
6
- device = 'cpu'
7
  seed = 42
8
- Generator = torch.Generator(device).manual_seed(seed)
9
- image_gen_steps = 35
10
- image_gen_model_id = 'stabilityai/stable-diffusion-2'
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' , guidance_scale=9
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
- ).image[0]
27
  image = image.resize(CFG.image_gen_size)
28
  return image
29
-
30
 
31
 
32
- title = "تصوَّر"
33
- description = "أدخل نص نحولها لك صوره"
34
 
35
- iface = gr.interface(fn=generate_image, inputs = "text", outputs = "image" , title= title , description=description)
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()