takahirox commited on
Commit
62f266f
1 Parent(s): 59bb425

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +55 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import StableDiffusionPipeline
2
+ from compel import Compel
3
+ import gradio
4
+ import torch
5
+
6
+ model_id = "dream-textures/texture-diffusion"
7
+ device = "cuda"
8
+ dtype = torch.float16
9
+
10
+ pipe = StableDiffusionPipeline.from_pretrained(
11
+ model_id, torch_dtype=dtype
12
+ ).to(device)
13
+ #pipe = StableDiffusionPipeline.from_pretrained(model_id)
14
+
15
+ compel_proc = Compel(
16
+ tokenizer=pipe.tokenizer,
17
+ text_encoder=pipe.text_encoder,
18
+ truncate_long_prompts=False,
19
+ )
20
+
21
+ def predict(
22
+ prompt: str,
23
+ generator: int,
24
+ num_inference_steps: int,
25
+ strength: float,
26
+ guidance_scale: float,
27
+ ):
28
+ generator = torch.manual_seed(generator)
29
+ prompt_embeds = compel_proc(prompt)
30
+
31
+ results = pipe(
32
+ prompt_embeds=prompt_embeds,
33
+ generator=generator,
34
+ guidance_scale=float(guidance_scale),
35
+ num_inference_steps=num_inference_steps,
36
+ output_type="pil",
37
+ strength=float(strength),
38
+ )
39
+
40
+ if len(results.images) > 0:
41
+ return results.images[0]
42
+ return None
43
+
44
+ app = gradio.Interface(
45
+ fn=predict,
46
+ inputs=[
47
+ gradio.Textbox("pbr brick wall"), # prompt
48
+ gradio.Slider(0, 2147483647, 2159232, step=1), # generator
49
+ gradio.Slider(2, 15, 4, step=1), # num_inference_steps
50
+ gradio.Slider(0.0, 1.0, 0.5, step=0.01), # strength
51
+ gradio.Slider(0.0, 5.0, 0.2, step=0.01), # guidance_scale
52
+ ],
53
+ outputs=gradio.Image(type="pil")
54
+ )
55
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ accelerate
2
+ compel
3
+ diffusers
4
+ gradio
5
+ torch