openfree commited on
Commit
70bfb09
·
verified ·
1 Parent(s): 0691ff2

Delete app-backup.py

Browse files
Files changed (1) hide show
  1. app-backup.py +0 -153
app-backup.py DELETED
@@ -1,153 +0,0 @@
1
- import gradio as gr
2
- import numpy as np
3
- import random
4
-
5
- import spaces
6
- from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler
7
- import torch
8
-
9
- device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "tensorart/stable-diffusion-3.5-large-TurboX"
11
-
12
- if torch.cuda.is_available():
13
- torch_dtype = torch.float16
14
- else:
15
- torch_dtype = torch.float32
16
-
17
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
-
19
- pipe.scheduler = FlowMatchEulerDiscreteScheduler.from_pretrained(model_repo_id, subfolder="scheduler", shift=5)
20
-
21
- pipe = pipe.to(device)
22
-
23
- MAX_SEED = np.iinfo(np.int32).max
24
- MAX_IMAGE_SIZE = 1024
25
-
26
- @spaces.GPU(duration=65)
27
- def infer(
28
- prompt,
29
- negative_prompt="",
30
- seed=42,
31
- randomize_seed=False,
32
- width=1024,
33
- height=1024,
34
- guidance_scale=1.5,
35
- num_inference_steps=8,
36
- progress=gr.Progress(track_tqdm=True),
37
- ):
38
- if randomize_seed:
39
- seed = random.randint(0, MAX_SEED)
40
-
41
- generator = torch.Generator().manual_seed(seed)
42
-
43
- image = pipe(
44
- prompt=prompt,
45
- negative_prompt=negative_prompt,
46
- guidance_scale=guidance_scale,
47
- num_inference_steps=num_inference_steps,
48
- width=width,
49
- height=height,
50
- generator=generator,
51
- ).images[0]
52
-
53
- return image, seed
54
-
55
-
56
- examples = [
57
- "A capybara wearing a suit holding a sign that reads Hello World",
58
- ]
59
-
60
- css = """
61
- #col-container {
62
- margin: 0 auto;
63
- max-width: 640px;
64
- }
65
- """
66
-
67
- with gr.Blocks(theme="apriel", css=css) as demo:
68
- with gr.Column(elem_id="col-container"):
69
- gr.Markdown(" # TensorArt Stable Diffusion 3.5 Large TurboX")
70
- gr.Markdown("[8-step distilled turbo model](https://huggingface.co/tensorart/stable-diffusion-3.5-large-TurboX)")
71
- with gr.Row():
72
- prompt = gr.Text(
73
- label="Prompt",
74
- show_label=False,
75
- max_lines=1,
76
- placeholder="Enter your prompt",
77
- container=False,
78
- )
79
-
80
- run_button = gr.Button("Run", scale=0, variant="primary")
81
-
82
- result = gr.Image(label="Result", show_label=False)
83
-
84
- with gr.Accordion("Advanced Settings", open=False):
85
- negative_prompt = gr.Text(
86
- label="Negative prompt",
87
- max_lines=1,
88
- placeholder="Enter a negative prompt",
89
- )
90
-
91
- seed = gr.Slider(
92
- label="Seed",
93
- minimum=0,
94
- maximum=MAX_SEED,
95
- step=1,
96
- value=0,
97
- )
98
-
99
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
100
-
101
- with gr.Row():
102
- width = gr.Slider(
103
- label="Width",
104
- minimum=512,
105
- maximum=MAX_IMAGE_SIZE,
106
- step=32,
107
- value=1024,
108
- )
109
-
110
- height = gr.Slider(
111
- label="Height",
112
- minimum=512,
113
- maximum=MAX_IMAGE_SIZE,
114
- step=32,
115
- value=1024,
116
- )
117
-
118
- with gr.Row():
119
- guidance_scale = gr.Slider(
120
- label="Guidance scale",
121
- minimum=0.0,
122
- maximum=7.5,
123
- step=0.1,
124
- value=1.5,
125
- )
126
-
127
- num_inference_steps = gr.Slider(
128
- label="Number of inference steps",
129
- minimum=1,
130
- maximum=50,
131
- step=1,
132
- value=8,
133
- )
134
-
135
- gr.Examples(examples=examples, inputs=[prompt], outputs=[result, seed], fn=infer, cache_examples=True, cache_mode="lazy")
136
- gr.on(
137
- triggers=[run_button.click, prompt.submit],
138
- fn=infer,
139
- inputs=[
140
- prompt,
141
- negative_prompt,
142
- seed,
143
- randomize_seed,
144
- width,
145
- height,
146
- guidance_scale,
147
- num_inference_steps,
148
- ],
149
- outputs=[result, seed],
150
- )
151
-
152
- if __name__ == "__main__":
153
- demo.launch()