prithivMLmods commited on
Commit
f73f36d
·
verified ·
1 Parent(s): 9dd9e5d

Delete LoRA

Browse files
Files changed (1) hide show
  1. LoRA/LoRA.txt +0 -193
LoRA/LoRA.txt DELETED
@@ -1,193 +0,0 @@
1
- import gradio as gr
2
- import spaces
3
- import numpy as np
4
- import random
5
- from diffusers import DiffusionPipeline
6
- import torch
7
- from PIL import Image
8
-
9
- device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/stable-diffusion-3.5-large-turbo"
11
-
12
- torch_dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
13
-
14
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
15
- pipe = pipe.to(device)
16
-
17
- pipe.load_lora_weights("prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA", weight_name="SD3.5-Turbo-Realism-2.0-LoRA.safetensors")
18
- trigger_word = "Turbo Realism"
19
- pipe.fuse_lora(lora_scale=1.0)
20
-
21
- MAX_SEED = np.iinfo(np.int32).max
22
- MAX_IMAGE_SIZE = 1024
23
-
24
- # Define styles
25
- style_list = [
26
- {
27
- "name": "3840 x 2160",
28
- "prompt": "hyper-realistic 8K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
29
- "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
30
- },
31
- {
32
- "name": "2560 x 1440",
33
- "prompt": "hyper-realistic 4K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
34
- "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
35
- },
36
- {
37
- "name": "HD+",
38
- "prompt": "hyper-realistic 2K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
39
- "negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
40
- },
41
- {
42
- "name": "Style Zero",
43
- "prompt": "{prompt}",
44
- "negative_prompt": "",
45
- },
46
- ]
47
-
48
- STYLE_NAMES = [style["name"] for style in style_list]
49
- DEFAULT_STYLE_NAME = STYLE_NAMES[0]
50
-
51
- grid_sizes = {
52
- "2x1": (2, 1),
53
- "1x2": (1, 2),
54
- "2x2": (2, 2),
55
- "2x3": (2, 3),
56
- "3x2": (3, 2),
57
- "1x1": (1, 1)
58
- }
59
-
60
- @spaces.GPU(duration=60)
61
- def infer(
62
- prompt,
63
- negative_prompt="",
64
- seed=42,
65
- randomize_seed=False,
66
- width=1024,
67
- height=1024,
68
- guidance_scale=7.5,
69
- num_inference_steps=10,
70
- style="Style Zero",
71
- grid_size="1x1",
72
- progress=gr.Progress(track_tqdm=True),
73
- ):
74
- selected_style = next(s for s in style_list if s["name"] == style)
75
- styled_prompt = selected_style["prompt"].format(prompt=prompt)
76
- styled_negative_prompt = selected_style["negative_prompt"]
77
-
78
- if randomize_seed:
79
- seed = random.randint(0, MAX_SEED)
80
-
81
- generator = torch.Generator().manual_seed(seed)
82
-
83
- grid_size_x, grid_size_y = grid_sizes.get(grid_size, (1, 1))
84
- num_images = grid_size_x * grid_size_y
85
-
86
- options = {
87
- "prompt": styled_prompt,
88
- "negative_prompt": styled_negative_prompt,
89
- "guidance_scale": guidance_scale,
90
- "num_inference_steps": num_inference_steps,
91
- "width": width,
92
- "height": height,
93
- "generator": generator,
94
- "num_images_per_prompt": num_images,
95
- }
96
-
97
- torch.cuda.empty_cache() # Clear GPU memory
98
- result = pipe(**options)
99
-
100
- grid_img = Image.new('RGB', (width * grid_size_x, height * grid_size_y))
101
-
102
- for i, img in enumerate(result.images[:num_images]):
103
- grid_img.paste(img, (i % grid_size_x * width, i // grid_size_x * height))
104
-
105
- return grid_img, seed
106
-
107
- examples = [
108
- "A tiny astronaut hatching from an egg on the moon, 4k, planet theme",
109
- "An anime-style illustration of a delicious, golden-brown wiener schnitzel on a plate, served with fresh lemon slices, parsley --style raw5",
110
- "Cold coffee in a cup bokeh --ar 85:128 --v 6.0 --style raw5, 4K, Photo-Realistic",
111
- "A cat holding a sign that says hello world --ar 85:128 --v 6.0 --style raw"
112
- ]
113
-
114
- css = '''
115
- .gradio-container {
116
- max-width: 585px !important;
117
- margin: 0 auto !important;
118
- display: flex;
119
- flex-direction: column;
120
- align-items: center;
121
- justify-content: center;
122
- }
123
- h1 { text-align: center; }
124
- footer { visibility: hidden; }
125
- '''
126
-
127
- with gr.Blocks(css=css) as demo:
128
- with gr.Column(elem_id="col-container"):
129
- gr.Markdown("## T2i Grid 6x")
130
-
131
- with gr.Row():
132
- prompt = gr.Text(
133
- show_label=False,
134
- max_lines=1,
135
- placeholder="Enter your prompt",
136
- container=False,
137
- )
138
- run_button = gr.Button("Run", scale=0, variant="primary")
139
-
140
- result = gr.Image(show_label=False)
141
-
142
- with gr.Row():
143
- grid_size_selection = gr.Dropdown(
144
- choices=list(grid_sizes.keys()),
145
- value="1x1",
146
- label="Grid Size"
147
- )
148
-
149
- with gr.Accordion("Advanced Settings", open=False):
150
- negative_prompt = gr.Text(
151
- label="Negative prompt",
152
- max_lines=1,
153
- placeholder="Enter a negative prompt",
154
- value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
155
- )
156
- seed = gr.Slider(0, MAX_SEED, value=0, label="Seed")
157
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
158
-
159
- with gr.Row():
160
- width = gr.Slider(512, MAX_IMAGE_SIZE, step=32, value=1024, label="Width")
161
- height = gr.Slider(512, MAX_IMAGE_SIZE, step=32, value=1024, label="Height")
162
-
163
- with gr.Row():
164
- guidance_scale = gr.Slider(0.0, 7.5, step=0.1, value=0.0, label="Guidance scale")
165
- num_inference_steps = gr.Slider(1, 50, step=1, value=10, label="Number of inference steps")
166
-
167
- style_selection = gr.Radio(
168
- choices=STYLE_NAMES,
169
- value=DEFAULT_STYLE_NAME,
170
- label="Quality Style",
171
- )
172
-
173
- gr.Examples(
174
- examples=examples,
175
- inputs=[prompt],
176
- outputs=[result, seed],
177
- fn=infer,
178
- cache_examples=False
179
- )
180
-
181
- gr.on(
182
- triggers=[run_button.click, prompt.submit],
183
- fn=infer,
184
- inputs=[
185
- prompt, negative_prompt, seed, randomize_seed,
186
- width, height, guidance_scale, num_inference_steps,
187
- style_selection, grid_size_selection
188
- ],
189
- outputs=[result, seed],
190
- )
191
-
192
- if __name__ == "__main__":
193
- demo.launch()