tomerkeren42 commited on
Commit
16eaad1
β€’
1 Parent(s): 15bfb07

Upload 6 files

Browse files
Files changed (6) hide show
  1. README.md +9 -7
  2. app.py +109 -0
  3. background-image.png +0 -0
  4. deci_logo_white.png +0 -0
  5. header.html +17 -0
  6. requirements.txt +8 -0
README.md CHANGED
@@ -1,12 +1,14 @@
1
  ---
2
- title: DeciDiffusion V1 0
3
- emoji: 🌍
4
- colorFrom: pink
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 3.44.0
8
  app_file: app.py
9
- pinned: false
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: DeciDiffusionClean
3
+ emoji: 🐨
4
+ colorFrom: purple
5
+ colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 3.43.2
8
  app_file: app.py
9
+ pinned: true
10
+ disable_embedding: true
11
+ inference: true
12
  ---
13
 
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from PIL.ImageDraw import Draw
4
+ from diffusers import StableDiffusionPipeline
5
+ from PIL import Image, ImageOps
6
+
7
+
8
+ # Load pipeline once
9
+ model_id = '/Users/tomerkeren/DeciDiffusion-1.0'
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, custom_pipeline=model_id, torch_dtype=torch.float32)
12
+ pipe.unet = pipe.unet.from_pretrained(model_id, subfolder='flexible_unet', torch_dtype=torch.float32)
13
+ pipe = pipe.to(device)
14
+
15
+
16
+ def read_content(file_path: str) -> str:
17
+ """read the content of target file
18
+ """
19
+ with open(file_path, 'r', encoding='utf-8') as f:
20
+ content = f.read()
21
+
22
+ return content
23
+
24
+
25
+ def predict(_prompt: str, _steps: int = 30, _seed: int = 42, _guidance_scale: float = 7.5, _negative_prompt: str = ""):
26
+ _negative_prompt = [_negative_prompt] if _negative_prompt else None
27
+
28
+ output = pipe(prompt=[_prompt],
29
+ negative_prompt=_negative_prompt,
30
+ num_inference_steps=int(_steps),
31
+ guidance_scale=_guidance_scale,
32
+ generator=torch.Generator(device).manual_seed(_seed),
33
+ )
34
+ output_image = output.images[0]
35
+
36
+ # Add border beneath the image with Deci logo + prompt
37
+ if len(_prompt) > 52:
38
+ _prompt = _prompt[:52] + "..."
39
+
40
+ original_image_height = output_image.size[1]
41
+ output_image = ImageOps.expand(output_image, border=(0, 0, 0, 64), fill='white')
42
+ deci_logo = Image.open('https://huggingface.co/spaces/Deci/DeciDiffusion-v1-0/resolve/main/deci_logo_white.png')
43
+ output_image.paste(deci_logo, (0, original_image_height))
44
+ Draw(output_image).text((deci_logo.size[0], original_image_height), _prompt, (127, 127, 127))
45
+ return output_image
46
+
47
+
48
+ css = '''
49
+ .gradio-container {
50
+ max-width: 1100px !important;
51
+ background-image: url(https://huggingface.co/spaces/Deci/Deci-DeciDiffusionClean/resolve/main/background-image.png);
52
+ background-size: cover;
53
+ background-position: center center;
54
+ background-repeat: no-repeat;
55
+ }
56
+
57
+ .footer {margin-bottom: 45px;margin-top: 35px !important;text-align: center;border-bottom: 1px solid #e5e5e5}
58
+ .footer>p {font-size: .8rem; display: inline-block; padding: 0 10px;transform: translateY(10px);background: white}
59
+ .dark .footer {border-color: #303030}
60
+ .dark .footer>p {background: #0b0f19}
61
+ .acknowledgments h4{margin: 1.25em 0 .25em 0;font-weight: bold;font-size: 115%}
62
+ @keyframes spin {
63
+ from {
64
+ transform: rotate(0deg);
65
+ }
66
+ to {
67
+ transform: rotate(360deg);
68
+ }
69
+ }
70
+ '''
71
+
72
+ demo = gr.Blocks(css=css, elem_id="total-container")
73
+ with demo:
74
+ gr.HTML(read_content("header.html"))
75
+ with gr.Row():
76
+ with gr.Column():
77
+ with gr.Row(mobile_collapse=False, equal_height=True):
78
+ prompt = gr.Textbox(placeholder="Your prompt", show_label=False, elem_id="prompt", autofocus=True, lines=3, )
79
+
80
+ with gr.Accordion(label="Advanced Settings", open=False):
81
+ with gr.Row(mobile_collapse=False, equal_height=True):
82
+ steps = gr.Slider(value=30, minimum=15, maximum=50, step=1, label="steps", interactive=True)
83
+ seed = gr.Slider(value=42, minimum=1, maximum=100, step=1, label="seed", interactive=True)
84
+ guidance_scale = gr.Slider(value=7.5, minimum=1, maximum=15, step=0.1, label='guidance_scale', interactive=True)
85
+
86
+ with gr.Row(mobile_collapse=False, equal_height=True):
87
+ negative_prompt = gr.Textbox(label="negative_prompt", placeholder="Your negative prompt",
88
+ info="what you don't want to see in the image", lines=3)
89
+ with gr.Row():
90
+ btn = gr.Button(value="Generate!", elem_id="run_button")
91
+
92
+ with gr.Column():
93
+ image_out = gr.Image(label="Output", elem_id="output-img", height=400)
94
+
95
+ btn.click(fn=predict,
96
+ inputs=[prompt, steps, seed, guidance_scale, negative_prompt],
97
+ outputs=[image_out],
98
+ api_name='run')
99
+
100
+ gr.HTML(
101
+ """
102
+ <div class="footer">
103
+ <p>Model by <a href="https://deci.ai" style="text-decoration: underline;" target="_blank">Deci.ai</a> - Gradio Demo by πŸ€— Hugging Face
104
+ </p>
105
+ </div>
106
+ """
107
+ )
108
+
109
+ demo.queue(max_size=50).launch()
background-image.png ADDED
deci_logo_white.png ADDED
header.html ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
2
+ <div style="
3
+ display: inline-flex;
4
+ gap: 0.8rem;
5
+ font-size: 1.75rem;
6
+ justify-content: center;
7
+ margin-bottom: 10px;
8
+ ">
9
+ <h1 style="font-weight: 900; align-items: center; margin-bottom: 7px; margin-top: 20px;">
10
+ Deci Diffusion
11
+ </h1>
12
+ </div>
13
+ <div>
14
+ <p style="align-items: center; margin-bottom: 7px;">
15
+ Demo for the <a href="https://huggingface.co/Deci/DeciDiffusion-v1-0" target="_blank">DeciDiffusion model</a>
16
+ </div>
17
+ </div>
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu118
2
+ torch
3
+ git+https://github.com/huggingface/diffusers.git
4
+ transformers
5
+ accelerate
6
+ ftfy
7
+ numpy
8
+ matplotlib