Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse filesoptimize examples, change theme style and add multi images gen
app.py
CHANGED
@@ -6,6 +6,8 @@ from huggingface_hub import hf_hub_download
|
|
6 |
from PIL import Image
|
7 |
import requests
|
8 |
from translatepy import Translator
|
|
|
|
|
9 |
|
10 |
translator = Translator()
|
11 |
|
@@ -21,21 +23,13 @@ footer {
|
|
21 |
}
|
22 |
"""
|
23 |
|
24 |
-
|
25 |
-
gradioURL = window.location.href
|
26 |
-
if (!gradioURL.endsWith('?__theme=dark')) {
|
27 |
-
window.location.replace(gradioURL + '?__theme=dark');
|
28 |
-
}
|
29 |
-
}"""
|
30 |
-
|
31 |
|
32 |
# Ensure model and scheduler are initialized in GPU-enabled function
|
33 |
if torch.cuda.is_available():
|
34 |
pipe = FluxPipeline.from_pretrained(model, torch_dtype=torch.bfloat16)
|
35 |
pipe.to("cuda")
|
36 |
|
37 |
-
|
38 |
-
|
39 |
# Function
|
40 |
@spaces.GPU()
|
41 |
def generate_image(
|
@@ -43,7 +37,16 @@ def generate_image(
|
|
43 |
width=768,
|
44 |
height=1024,
|
45 |
scale=3.5,
|
46 |
-
steps=24
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
prompt = str(translator.translate(prompt, 'English'))
|
49 |
|
@@ -55,29 +58,32 @@ def generate_image(
|
|
55 |
height=height,
|
56 |
guidance_scale=scale,
|
57 |
num_inference_steps=steps,
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
62 |
|
63 |
examples = [
|
64 |
"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.",
|
65 |
-
"
|
66 |
-
"
|
67 |
-
"
|
68 |
]
|
69 |
|
70 |
|
71 |
# Gradio Interface
|
72 |
|
73 |
-
with gr.Blocks(css=CSS,
|
74 |
-
gr.HTML("<h1><center>
|
75 |
gr.HTML("<p><center><a href='https://huggingface.co/Shakker-Labs/AWPortrait-FL'>Shakker-Labs/AWPortrait-FL</a></center></p>")
|
76 |
with gr.Group():
|
77 |
with gr.Row():
|
78 |
prompt = gr.Textbox(label='Enter Your Prompt(multilingual)', scale=6)
|
79 |
submit = gr.Button(scale=1, variant='primary')
|
80 |
-
img = gr.
|
81 |
with gr.Accordion("Advanced Options", open=False):
|
82 |
with gr.Row():
|
83 |
width = gr.Slider(
|
@@ -108,7 +114,24 @@ with gr.Blocks(css=CSS, js=JS, theme="soft") as demo:
|
|
108 |
maximum=50,
|
109 |
step=1,
|
110 |
value=24,
|
111 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
gr.Examples(
|
113 |
examples=examples,
|
114 |
inputs=prompt,
|
@@ -117,13 +140,23 @@ with gr.Blocks(css=CSS, js=JS, theme="soft") as demo:
|
|
117 |
cache_examples="lazy",
|
118 |
)
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
demo.queue().launch()
|
|
|
6 |
from PIL import Image
|
7 |
import requests
|
8 |
from translatepy import Translator
|
9 |
+
import numpy as np
|
10 |
+
import random
|
11 |
|
12 |
translator = Translator()
|
13 |
|
|
|
23 |
}
|
24 |
"""
|
25 |
|
26 |
+
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Ensure model and scheduler are initialized in GPU-enabled function
|
29 |
if torch.cuda.is_available():
|
30 |
pipe = FluxPipeline.from_pretrained(model, torch_dtype=torch.bfloat16)
|
31 |
pipe.to("cuda")
|
32 |
|
|
|
|
|
33 |
# Function
|
34 |
@spaces.GPU()
|
35 |
def generate_image(
|
|
|
37 |
width=768,
|
38 |
height=1024,
|
39 |
scale=3.5,
|
40 |
+
steps=24,
|
41 |
+
seed=-1,
|
42 |
+
nums=1,
|
43 |
+
progress=gr.Progress(track_tqdm=True)
|
44 |
+
):
|
45 |
+
if seed == -1:
|
46 |
+
seed = random.randint(0, MAX_SEED)
|
47 |
+
seed = int(seed)
|
48 |
+
|
49 |
+
generator = torch.Generator().manual_seed(seed)
|
50 |
|
51 |
prompt = str(translator.translate(prompt, 'English'))
|
52 |
|
|
|
58 |
height=height,
|
59 |
guidance_scale=scale,
|
60 |
num_inference_steps=steps,
|
61 |
+
generator=generator,
|
62 |
+
output_type="pil",
|
63 |
+
max_sequence_length=512,
|
64 |
+
num_images_per_prompt=nums,
|
65 |
+
).images
|
66 |
+
|
67 |
+
return image, seed
|
68 |
|
69 |
examples = [
|
70 |
"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.",
|
71 |
+
"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",
|
72 |
+
"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",
|
73 |
+
"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"
|
74 |
]
|
75 |
|
76 |
|
77 |
# Gradio Interface
|
78 |
|
79 |
+
with gr.Blocks(css=CSS, theme="xiaobaiyuan/theme_brief") as demo:
|
80 |
+
gr.HTML("<h1><center>AWPortrait-FL</center></h1>")
|
81 |
gr.HTML("<p><center><a href='https://huggingface.co/Shakker-Labs/AWPortrait-FL'>Shakker-Labs/AWPortrait-FL</a></center></p>")
|
82 |
with gr.Group():
|
83 |
with gr.Row():
|
84 |
prompt = gr.Textbox(label='Enter Your Prompt(multilingual)', scale=6)
|
85 |
submit = gr.Button(scale=1, variant='primary')
|
86 |
+
img = gr.Gallery(label="Gallery", columns = 1, preview=True)
|
87 |
with gr.Accordion("Advanced Options", open=False):
|
88 |
with gr.Row():
|
89 |
width = gr.Slider(
|
|
|
114 |
maximum=50,
|
115 |
step=1,
|
116 |
value=24,
|
117 |
+
)
|
118 |
+
with gr.Row():
|
119 |
+
seed = gr.Slider(
|
120 |
+
label="Seed(-1 Random)",
|
121 |
+
minimum=-1,
|
122 |
+
maximum=MAX_SEED,
|
123 |
+
step=1,
|
124 |
+
value=0,
|
125 |
+
visible=True
|
126 |
+
)
|
127 |
+
nums = gr.Slider(
|
128 |
+
label="Image Numbers",
|
129 |
+
minimum=1,
|
130 |
+
maximum=4,
|
131 |
+
step=1,
|
132 |
+
value=1,
|
133 |
+
scale=1,
|
134 |
+
)
|
135 |
gr.Examples(
|
136 |
examples=examples,
|
137 |
inputs=prompt,
|
|
|
140 |
cache_examples="lazy",
|
141 |
)
|
142 |
|
143 |
+
gr.on(
|
144 |
+
triggers=[
|
145 |
+
prompt.submit,
|
146 |
+
submit.click,
|
147 |
+
],
|
148 |
+
fn=generate_image,
|
149 |
+
inputs=[
|
150 |
+
prompt,
|
151 |
+
width,
|
152 |
+
height,
|
153 |
+
scale,
|
154 |
+
steps,
|
155 |
+
seed,
|
156 |
+
nums
|
157 |
+
],
|
158 |
+
outputs=[img, seed],
|
159 |
+
api_name="run",
|
160 |
+
)
|
161 |
|
162 |
demo.queue().launch()
|