Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,8 @@ import random
|
|
7 |
from diffusers import FluxPipeline
|
8 |
from translatepy import Translator
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
-
|
|
|
11 |
|
12 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
13 |
translator = Translator()
|
@@ -31,11 +32,41 @@ JS = """function () {
|
|
31 |
|
32 |
if torch.cuda.is_available():
|
33 |
pipe = FluxPipeline.from_pretrained(model, torch_dtype=torch.bfloat16)
|
34 |
-
pipe.load_lora_weights("Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration", weight_name="FLUX-dev-lora-blended_realistic_illustration.safetensors")
|
35 |
-
pipe.fuse_lora(lora_scale=1.0)
|
36 |
-
pipe.to(device="cuda", dtype=torch.bfloat16)
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
@spaces.GPU()
|
40 |
def generate_image(
|
41 |
prompt,
|
@@ -43,7 +74,7 @@ def generate_image(
|
|
43 |
height=1024,
|
44 |
scales=5,
|
45 |
steps=24,
|
46 |
-
seed
|
47 |
nums=1,
|
48 |
progress=gr.Progress(track_tqdm=True)):
|
49 |
|
@@ -72,6 +103,22 @@ def generate_image(
|
|
72 |
return image, seed
|
73 |
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
examples_bak = [
|
76 |
"a female character with long, flowing hair that appears to be made of ethereal, swirling patterns resembling the Northern Lights or Aurora Borealis. The background is dominated by deep blues and purples, creating a mysterious and dramatic atmosphere. The character's face is serene, with pale skin and striking features. She wears a dark-colored outfit with subtle patterns. The overall style of the artwork is reminiscent of fantasy or supernatural genres",
|
77 |
"Digital art, portrait of an anthropomorphic roaring Tiger warrior with full armor, close up in the middle of a battle, behind him there is a banner with the text \"Open Source\".",
|
@@ -90,8 +137,10 @@ examples = [
|
|
90 |
"A cartoon style European woman wearing glasses is eating a table of seafood,including lobster,oysters,and other shellfish,in a well lit modern restaurant. The background of the restaurant is very blurry,and she is holding the utensils ready to eat. There is a glass of red wine and various dishes on the table. The illustrations contrast with the real food and environment,creating a unique mixed media effect and high angle perspective",
|
91 |
"A cartoon style European man opens his hands and takes a selfie under the Sydney Opera House",
|
92 |
"Against the backdrop of the Eiffel Tower, a cartoon style European woman wearing a delicate white floral dress stands there, with the iconic building of the tower clearly visible under the azure sky, capturing the romantic charm of Paris. When she takes photos against this stunning background, her flowing hair adds a dreamy atmosphere",
|
93 |
-
"
|
94 |
-
"
|
|
|
|
|
95 |
]
|
96 |
|
97 |
|
@@ -99,7 +148,7 @@ examples = [
|
|
99 |
|
100 |
with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
101 |
gr.HTML("<h1><center>Flux Labs</center></h1>")
|
102 |
-
gr.HTML("<p><center>
|
103 |
with gr.Row():
|
104 |
with gr.Column(scale=4):
|
105 |
img = gr.Gallery(label='flux Generated Image', columns = 1, preview=True, height=600)
|
@@ -142,7 +191,6 @@ with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
|
142 |
maximum=MAX_SEED,
|
143 |
step=1,
|
144 |
value=-1,
|
145 |
-
scale=2,
|
146 |
)
|
147 |
nums = gr.Slider(
|
148 |
label="Image Numbers",
|
@@ -150,25 +198,57 @@ with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
|
150 |
maximum=4,
|
151 |
step=1,
|
152 |
value=1,
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
gr.Examples(
|
156 |
examples=examples,
|
157 |
-
inputs=prompt,
|
158 |
outputs=[img, seed],
|
159 |
-
fn=
|
160 |
cache_examples="lazy",
|
161 |
examples_per_page=4,
|
162 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
-
sendBtn.click(fn=generate_image,
|
165 |
-
inputs=[prompt, width, height, scales, steps, seed, nums],
|
166 |
-
outputs=[img, seed],
|
167 |
-
)
|
168 |
-
prompt.submit(fn=generate_image,
|
169 |
-
inputs=[prompt, width, height, scales, steps, seed, nums],
|
170 |
-
outputs=[img, seed],
|
171 |
-
)
|
172 |
|
173 |
|
174 |
demo.queue().launch()
|
|
|
7 |
from diffusers import FluxPipeline
|
8 |
from translatepy import Translator
|
9 |
from huggingface_hub import hf_hub_download
|
10 |
+
import requests
|
11 |
+
import re
|
12 |
|
13 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
14 |
translator = Translator()
|
|
|
32 |
|
33 |
if torch.cuda.is_available():
|
34 |
pipe = FluxPipeline.from_pretrained(model, torch_dtype=torch.bfloat16)
|
|
|
|
|
|
|
35 |
|
36 |
+
|
37 |
+
def scrape_lora_link(url):
|
38 |
+
try:
|
39 |
+
# Send a GET request to the URL
|
40 |
+
response = requests.get(url)
|
41 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
42 |
+
|
43 |
+
# Get the content of the page
|
44 |
+
content = response.text
|
45 |
+
|
46 |
+
# Use regular expression to find the link
|
47 |
+
pattern = r'href="(.*?lora.*?\.safetensors\?download=true)"'
|
48 |
+
match = re.search(pattern, content)
|
49 |
+
|
50 |
+
if match:
|
51 |
+
safetensors_url = match.group(1)
|
52 |
+
filename = safetensors_url.split('/')[-1].split('?')[0] # Extract the filename from the URL
|
53 |
+
return filename
|
54 |
+
else:
|
55 |
+
return None
|
56 |
+
|
57 |
+
except requests.RequestException as e:
|
58 |
+
print(f"An error occurred while fetching the URL: {e}")
|
59 |
+
return None
|
60 |
+
|
61 |
+
def enable_lora(lora_scale, lora_in, lora_add):
|
62 |
+
if load_in:
|
63 |
+
lora_add = load_in
|
64 |
+
url = f'https://huggingface.co/{lora_add}/tree/main'
|
65 |
+
lora_name = scrape_lora_link(url)
|
66 |
+
pipe.load_lora_weights(lora_add, weight_name=lora_name)
|
67 |
+
pipe.fuse_lora(lora_scale=lora_scale)
|
68 |
+
pipe.to(device="cuda", dtype=torch.bfloat16)
|
69 |
+
|
70 |
@spaces.GPU()
|
71 |
def generate_image(
|
72 |
prompt,
|
|
|
74 |
height=1024,
|
75 |
scales=5,
|
76 |
steps=24,
|
77 |
+
seed=-1,
|
78 |
nums=1,
|
79 |
progress=gr.Progress(track_tqdm=True)):
|
80 |
|
|
|
103 |
return image, seed
|
104 |
|
105 |
|
106 |
+
def gen(
|
107 |
+
prompt,
|
108 |
+
width=768,
|
109 |
+
height=1024,
|
110 |
+
scales=5,
|
111 |
+
steps=24,
|
112 |
+
seed=-1,
|
113 |
+
nums=1,
|
114 |
+
lora_scale=1.0,
|
115 |
+
lora_in="",
|
116 |
+
lora_add=""
|
117 |
+
):
|
118 |
+
enable_lora(lora_scale, lora_in, lora_add)
|
119 |
+
generate_image(prompt,width,height,scales,steps,seed,nums)
|
120 |
+
|
121 |
+
|
122 |
examples_bak = [
|
123 |
"a female character with long, flowing hair that appears to be made of ethereal, swirling patterns resembling the Northern Lights or Aurora Borealis. The background is dominated by deep blues and purples, creating a mysterious and dramatic atmosphere. The character's face is serene, with pale skin and striking features. She wears a dark-colored outfit with subtle patterns. The overall style of the artwork is reminiscent of fantasy or supernatural genres",
|
124 |
"Digital art, portrait of an anthropomorphic roaring Tiger warrior with full armor, close up in the middle of a battle, behind him there is a banner with the text \"Open Source\".",
|
|
|
137 |
"A cartoon style European woman wearing glasses is eating a table of seafood,including lobster,oysters,and other shellfish,in a well lit modern restaurant. The background of the restaurant is very blurry,and she is holding the utensils ready to eat. There is a glass of red wine and various dishes on the table. The illustrations contrast with the real food and environment,creating a unique mixed media effect and high angle perspective",
|
138 |
"A cartoon style European man opens his hands and takes a selfie under the Sydney Opera House",
|
139 |
"Against the backdrop of the Eiffel Tower, a cartoon style European woman wearing a delicate white floral dress stands there, with the iconic building of the tower clearly visible under the azure sky, capturing the romantic charm of Paris. When she takes photos against this stunning background, her flowing hair adds a dreamy atmosphere",
|
140 |
+
"close up portrait, Amidst the interplay of light and shadows in a photography studio,a soft spotlight traces the contours of a face,highlighting a figure clad in a sleek black turtleneck. The garment,hugging the skin with subtle luxury,complements the Caucasian model's understated makeup,embodying minimalist elegance. Behind,a pale gray backdrop extends,its fine texture shimmering subtly in the dim light,artfully balancing the composition and focusing attention on the subject. In a palette of black,gray,and skin tones,simplicity intertwines with profundity,as every detail whispers untold stories.",
|
141 |
+
"Caucasian,The image features a young woman of European descent standing in an studio setting,surrounded by silk. (She is wearing a silk dress),paired with a bold. Her brown hair is wet and tousled,falling naturally around her face,giving her a raw and edgy look. The woman has an intense and direct gaze,adding to the dramatic feel of the image. The backdrop is flowing silk,big silk. The overall composition blends elements of fashion and nature,creating a striking and powerful visual",
|
142 |
+
"A black and white portrait of a young woman with a captivating gaze. She's bundled up in a cozy black sweater,hands gently cupped near her face. The monochromatic tones highlight her delicate features and the contemplative mood of the image",
|
143 |
+
"Fashion photography portrait,close up portrait,(a woman of European descent is surrounded by lava rock and magma from head to neck, red magma hair, wear volcanic lava rock magma outfit coat lava rock magma fashion costume with ruffled layers"
|
144 |
]
|
145 |
|
146 |
|
|
|
148 |
|
149 |
with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
150 |
gr.HTML("<h1><center>Flux Labs</center></h1>")
|
151 |
+
gr.HTML("<p><center>Choose the LoRA model on the right menu</center></p>")
|
152 |
with gr.Row():
|
153 |
with gr.Column(scale=4):
|
154 |
img = gr.Gallery(label='flux Generated Image', columns = 1, preview=True, height=600)
|
|
|
191 |
maximum=MAX_SEED,
|
192 |
step=1,
|
193 |
value=-1,
|
|
|
194 |
)
|
195 |
nums = gr.Slider(
|
196 |
label="Image Numbers",
|
|
|
198 |
maximum=4,
|
199 |
step=1,
|
200 |
value=1,
|
201 |
+
)
|
202 |
+
lora_scale = gr.Slider(
|
203 |
+
label="LoRA Scale",
|
204 |
+
minimum=0.1,
|
205 |
+
maximum=1.0,
|
206 |
+
step=0.1,
|
207 |
+
value=1.0,
|
208 |
+
)
|
209 |
+
lora_in = gr.Dropdown(
|
210 |
+
["Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration", "Shakker-Labs/AWPortrait-FL", ""],
|
211 |
+
label="LoRA Model",
|
212 |
+
info="Load the LoRA",
|
213 |
+
values="Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration"
|
214 |
+
)
|
215 |
+
lora_add = gr.Textbox(
|
216 |
+
label="Add Flux LoRA",
|
217 |
+
info="Copy the HF LoRA model name here",
|
218 |
+
lines=1,
|
219 |
+
value="",
|
220 |
+
)
|
221 |
gr.Examples(
|
222 |
examples=examples,
|
223 |
+
inputs=[prompt,lora_scale,lora_in],
|
224 |
outputs=[img, seed],
|
225 |
+
fn=gen,
|
226 |
cache_examples="lazy",
|
227 |
examples_per_page=4,
|
228 |
)
|
229 |
+
|
230 |
+
gr.on(
|
231 |
+
triggers=[
|
232 |
+
prompt.submit,
|
233 |
+
submit.click,
|
234 |
+
],
|
235 |
+
fn=gen,
|
236 |
+
inputs=[
|
237 |
+
prompt,
|
238 |
+
width,
|
239 |
+
height,
|
240 |
+
scales,
|
241 |
+
steps,
|
242 |
+
seed,
|
243 |
+
nums,
|
244 |
+
lora_scale,
|
245 |
+
lora_in,
|
246 |
+
lora_add
|
247 |
+
],
|
248 |
+
outputs=[img, seed],
|
249 |
+
api_name="run",
|
250 |
+
)
|
251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
|
253 |
|
254 |
demo.queue().launch()
|