Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from diffusers import
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
-
import spaces
|
6 |
from PIL import Image
|
7 |
import requests
|
8 |
from translatepy import Translator
|
@@ -10,8 +10,7 @@ from translatepy import Translator
|
|
10 |
translator = Translator()
|
11 |
|
12 |
# Constants
|
13 |
-
model = "
|
14 |
-
vae_model = "madebyollin/sdxl-vae-fp16-fix"
|
15 |
|
16 |
CSS = """
|
17 |
.gradio-container {
|
@@ -29,15 +28,11 @@ JS = """function () {
|
|
29 |
}
|
30 |
}"""
|
31 |
|
32 |
-
# Load VAE component
|
33 |
-
vae = AutoencoderKL.from_pretrained(
|
34 |
-
vae_model,
|
35 |
-
torch_dtype=torch.float16
|
36 |
-
)
|
37 |
|
38 |
# Ensure model and scheduler are initialized in GPU-enabled function
|
39 |
if torch.cuda.is_available():
|
40 |
-
pipe =
|
|
|
41 |
|
42 |
|
43 |
|
@@ -46,12 +41,13 @@ if torch.cuda.is_available():
|
|
46 |
def generate_image(
|
47 |
prompt,
|
48 |
negative="low quality",
|
49 |
-
width=
|
50 |
height=1024,
|
51 |
-
scale=
|
52 |
-
steps=
|
53 |
|
54 |
prompt = str(translator.translate(prompt, 'English'))
|
|
|
55 |
|
56 |
print(f'prompt:{prompt}')
|
57 |
|
@@ -68,26 +64,23 @@ def generate_image(
|
|
68 |
|
69 |
|
70 |
examples = [
|
71 |
-
"a
|
72 |
-
"
|
73 |
-
"
|
74 |
-
"
|
75 |
-
"Astronaut in a jungle, cold color palette, oil pastel, detailed, 8k",
|
76 |
-
"An alien holding sign board contain word 'Flash', futuristic, neonpunk",
|
77 |
-
"Kids going to school, Anime style"
|
78 |
]
|
79 |
|
80 |
|
81 |
# Gradio Interface
|
82 |
|
83 |
with gr.Blocks(css=CSS, js=JS, theme="soft") as demo:
|
84 |
-
gr.HTML("<h1><center>
|
85 |
-
gr.HTML("<p><center><a href='https://huggingface.co/
|
86 |
with gr.Group():
|
87 |
with gr.Row():
|
88 |
-
prompt = gr.Textbox(label='Enter Your Prompt', scale=6)
|
89 |
submit = gr.Button(scale=1, variant='primary')
|
90 |
-
img = gr.Image(label='
|
91 |
with gr.Accordion("Advanced Options", open=False):
|
92 |
with gr.Row():
|
93 |
negative = gr.Textbox(label="Negative prompt", value="low quality")
|
@@ -97,7 +90,7 @@ with gr.Blocks(css=CSS, js=JS, theme="soft") as demo:
|
|
97 |
minimum=512,
|
98 |
maximum=1280,
|
99 |
step=8,
|
100 |
-
value=
|
101 |
)
|
102 |
height = gr.Slider(
|
103 |
label="Height",
|
@@ -112,14 +105,14 @@ with gr.Blocks(css=CSS, js=JS, theme="soft") as demo:
|
|
112 |
minimum=0,
|
113 |
maximum=50,
|
114 |
step=0.1,
|
115 |
-
value=
|
116 |
)
|
117 |
steps = gr.Slider(
|
118 |
label="Steps",
|
119 |
minimum=1,
|
120 |
maximum=50,
|
121 |
step=1,
|
122 |
-
value=
|
123 |
)
|
124 |
gr.Examples(
|
125 |
examples=examples,
|
|
|
1 |
+
import spaces
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
+
from diffusers import FluxPipeline
|
5 |
from huggingface_hub import hf_hub_download
|
|
|
6 |
from PIL import Image
|
7 |
import requests
|
8 |
from translatepy import Translator
|
|
|
10 |
translator = Translator()
|
11 |
|
12 |
# Constants
|
13 |
+
model = "Shakker-Labs/AWPortrait-FL"
|
|
|
14 |
|
15 |
CSS = """
|
16 |
.gradio-container {
|
|
|
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 |
|
|
|
41 |
def generate_image(
|
42 |
prompt,
|
43 |
negative="low quality",
|
44 |
+
width=768,
|
45 |
height=1024,
|
46 |
+
scale=3.5,
|
47 |
+
steps=24):
|
48 |
|
49 |
prompt = str(translator.translate(prompt, 'English'))
|
50 |
+
negative_prompt = str(translator.translate(negative, 'English'))
|
51 |
|
52 |
print(f'prompt:{prompt}')
|
53 |
|
|
|
64 |
|
65 |
|
66 |
examples = [
|
67 |
+
"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.",
|
68 |
+
"upper body portrait of 1girl wear a black color turtleneck sweater,A proud and confident expression,long hair,look at viewers,studio fashion portrait,studio light,pure white background",
|
69 |
+
"upper body portrait of 1girl wear (red color turtleneck sweater:1),A proud and confident smile expression,long hair,look at viewers,studio fashion portrait,studio light,pure white background",
|
70 |
+
"upper body portrait of 1girl wear suit with tie,A proud and confident smile expression,long hair,look at viewers,studio fashion portrait,studio light,pure white background"
|
|
|
|
|
|
|
71 |
]
|
72 |
|
73 |
|
74 |
# Gradio Interface
|
75 |
|
76 |
with gr.Blocks(css=CSS, js=JS, theme="soft") as demo:
|
77 |
+
gr.HTML("<h1><center>Flux</center></h1>")
|
78 |
+
gr.HTML("<p><center><a href='https://huggingface.co/Shakker-Labs/AWPortrait-FL'>Shakker-Labs/AWPortrait-FL</a></center></p>")
|
79 |
with gr.Group():
|
80 |
with gr.Row():
|
81 |
+
prompt = gr.Textbox(label='Enter Your Prompt(multilingual)', scale=6)
|
82 |
submit = gr.Button(scale=1, variant='primary')
|
83 |
+
img = gr.Image(label='Flux Generated Image')
|
84 |
with gr.Accordion("Advanced Options", open=False):
|
85 |
with gr.Row():
|
86 |
negative = gr.Textbox(label="Negative prompt", value="low quality")
|
|
|
90 |
minimum=512,
|
91 |
maximum=1280,
|
92 |
step=8,
|
93 |
+
value=768,
|
94 |
)
|
95 |
height = gr.Slider(
|
96 |
label="Height",
|
|
|
105 |
minimum=0,
|
106 |
maximum=50,
|
107 |
step=0.1,
|
108 |
+
value=3.5,
|
109 |
)
|
110 |
steps = gr.Slider(
|
111 |
label="Steps",
|
112 |
minimum=1,
|
113 |
maximum=50,
|
114 |
step=1,
|
115 |
+
value=24,
|
116 |
)
|
117 |
gr.Examples(
|
118 |
examples=examples,
|