Spaces:
Running
Running
salomonsky
commited on
Commit
•
b20c582
1
Parent(s):
838168c
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
#Save ZeroGPU limited resources, switch to InferenceAPI
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
@@ -12,7 +11,6 @@ from PIL import Image
|
|
12 |
|
13 |
translator = Translator()
|
14 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
15 |
-
# Constants
|
16 |
basemodel = "black-forest-labs/FLUX.1-dev"
|
17 |
MAX_SEED = np.iinfo(np.int32).max
|
18 |
|
@@ -67,103 +65,112 @@ async def generate_image(
|
|
67 |
|
68 |
return image, seed
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
async def gen(
|
71 |
prompt:str,
|
72 |
-
lora_add:str="",
|
73 |
lora_word:str="",
|
74 |
width:int=768,
|
75 |
height:int=1024,
|
76 |
scales:float=3.5,
|
77 |
steps:int=24,
|
78 |
seed:int=-1,
|
|
|
79 |
progress=gr.Progress(track_tqdm=True)
|
80 |
):
|
81 |
model = enable_lora(lora_add)
|
82 |
print(model)
|
83 |
image, seed = await generate_image(prompt,model,lora_word,width,height,scales,steps,seed)
|
84 |
-
|
|
|
85 |
|
86 |
-
examples = [
|
87 |
-
["a seal holding a beach ball in a pool","bingbangboom/flux_dreamscape","in the style of BSstyle004"],
|
88 |
-
["1980s anime screengrab, VHS quality, a woman with her face glitching and disorted, a halo above her head","dataautogpt3/FLUX-SyntheticAnime","1980s anime screengrab, VHS quality"],
|
89 |
-
["photograph, background of Earth from space, red car on the Moon watching Earth","martintomov/retrofuturism-flux","retrofuturism"],
|
90 |
-
["a living room interior","fofr/flux-80s-cyberpunk","80s cyberpunk"],
|
91 |
-
["Shrek, a lovable green ogre with a big smile, sitting on a moss-covered rock while enjoying a plate of freshly picked vegetables, in a magical forest filled with whimsical creatures, dappled sunlight filtering through the trees, surrounded by curious fairies peeking out from behind leaves","alvarobartt/ghibli-characters-flux-lora","Ghibli style"],
|
92 |
-
["a tourist in London, illustration in the style of VCTRNDRWNG, Victorian-era drawing","dvyio/flux-lora-victorian-drawing","illustration in the style of VCTRNDRWNG"],
|
93 |
-
["an African American and a caucasian man petting a cat at a busy electronic store. flikr photo from 2012. three people working in the background","kudzueye/boreal-flux-dev-v2","photo"],
|
94 |
-
["mgwr/cine, woman silhouette, morning light, sun rays, indoor scene, soft focus, golden hour, stretching pose, peaceful mood, cozy atmosphere, window light, shadows and highlights, backlit figure, minimalistic interior, warm tones, contemplative moment, calm energy, serene environment, yoga-inspired, elegant posture, natural light beams, artistic composition","mgwr/Cine-Aesthetic","atmospheric lighting and a dreamy, surreal vibe"]
|
95 |
-
]
|
96 |
-
|
97 |
-
# Gradio Interface
|
98 |
-
|
99 |
with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
100 |
gr.HTML("<h1><center>Flux Lab Light</center></h1>")
|
101 |
-
gr.HTML("<p><center>Powered By HF Inference API</center></p>")
|
102 |
with gr.Row():
|
103 |
with gr.Column(scale=4):
|
104 |
with gr.Row():
|
105 |
-
img = gr.Image(type="filepath", label='
|
106 |
with gr.Row():
|
107 |
-
prompt = gr.Textbox(label='
|
108 |
sendBtn = gr.Button(scale=1, variant='primary')
|
109 |
-
with gr.Accordion("
|
110 |
with gr.Column(scale=1):
|
111 |
width = gr.Slider(
|
112 |
-
label="
|
113 |
minimum=512,
|
114 |
maximum=1280,
|
115 |
step=8,
|
116 |
value=768,
|
117 |
)
|
118 |
height = gr.Slider(
|
119 |
-
label="
|
120 |
minimum=512,
|
121 |
maximum=1280,
|
122 |
step=8,
|
123 |
value=1024,
|
124 |
)
|
125 |
scales = gr.Slider(
|
126 |
-
label="
|
127 |
minimum=3.5,
|
128 |
maximum=7,
|
129 |
step=0.1,
|
130 |
value=3.5,
|
131 |
)
|
132 |
steps = gr.Slider(
|
133 |
-
label="
|
134 |
minimum=1,
|
135 |
maximum=100,
|
136 |
step=1,
|
137 |
value=24,
|
138 |
)
|
139 |
seed = gr.Slider(
|
140 |
-
label="
|
141 |
minimum=-1,
|
142 |
maximum=MAX_SEED,
|
143 |
step=1,
|
144 |
value=-1,
|
145 |
)
|
146 |
lora_add = gr.Textbox(
|
147 |
-
label="
|
148 |
-
info="
|
149 |
lines=1,
|
150 |
-
|
151 |
)
|
152 |
lora_word = gr.Textbox(
|
153 |
-
label="
|
154 |
-
info="
|
155 |
lines=1,
|
156 |
value="",
|
157 |
)
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
fn=gen,
|
164 |
-
cache_examples="lazy",
|
165 |
-
examples_per_page=4,
|
166 |
-
)
|
167 |
|
168 |
gr.on(
|
169 |
triggers=[
|
@@ -179,7 +186,8 @@ with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
|
179 |
height,
|
180 |
scales,
|
181 |
steps,
|
182 |
-
seed
|
|
|
183 |
],
|
184 |
outputs=[img, seed]
|
185 |
)
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
|
|
11 |
|
12 |
translator = Translator()
|
13 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
|
14 |
basemodel = "black-forest-labs/FLUX.1-dev"
|
15 |
MAX_SEED = np.iinfo(np.int32).max
|
16 |
|
|
|
65 |
|
66 |
return image, seed
|
67 |
|
68 |
+
async def upscale_image(image, upscale_factor):
|
69 |
+
client = AsyncInferenceClient()
|
70 |
+
try:
|
71 |
+
result = await client.predict(
|
72 |
+
input_image=image,
|
73 |
+
prompt="",
|
74 |
+
negative_prompt="",
|
75 |
+
seed=42,
|
76 |
+
upscale_factor=upscale_factor,
|
77 |
+
controlnet_scale=0.6,
|
78 |
+
controlnet_decay=1,
|
79 |
+
condition_scale=6,
|
80 |
+
tile_width=112,
|
81 |
+
tile_height=144,
|
82 |
+
denoise_strength=0.35,
|
83 |
+
num_inference_steps=18,
|
84 |
+
solver="DDIM",
|
85 |
+
api_name="/process",
|
86 |
+
model="finegrain/finegrain-image-enhancer"
|
87 |
+
)
|
88 |
+
except Exception as e:
|
89 |
+
raise gr.Error(f"Error in {e}")
|
90 |
+
|
91 |
+
return result[1]
|
92 |
+
|
93 |
async def gen(
|
94 |
prompt:str,
|
95 |
+
lora_add:str="XLabs-AI/flux-RealismLora",
|
96 |
lora_word:str="",
|
97 |
width:int=768,
|
98 |
height:int=1024,
|
99 |
scales:float=3.5,
|
100 |
steps:int=24,
|
101 |
seed:int=-1,
|
102 |
+
upscale_factor:int=2,
|
103 |
progress=gr.Progress(track_tqdm=True)
|
104 |
):
|
105 |
model = enable_lora(lora_add)
|
106 |
print(model)
|
107 |
image, seed = await generate_image(prompt,model,lora_word,width,height,scales,steps,seed)
|
108 |
+
upscaled_image = await upscale_image(image, upscale_factor)
|
109 |
+
return upscaled_image, seed
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
112 |
gr.HTML("<h1><center>Flux Lab Light</center></h1>")
|
|
|
113 |
with gr.Row():
|
114 |
with gr.Column(scale=4):
|
115 |
with gr.Row():
|
116 |
+
img = gr.Image(type="filepath", label='Imagen generada por Flux', height=600)
|
117 |
with gr.Row():
|
118 |
+
prompt = gr.Textbox(label='Ingresa tu prompt (Multi-Idiomas)', placeholder="Ingresa prompt...", scale=6)
|
119 |
sendBtn = gr.Button(scale=1, variant='primary')
|
120 |
+
with gr.Accordion("Opciones avanzadas", open=True):
|
121 |
with gr.Column(scale=1):
|
122 |
width = gr.Slider(
|
123 |
+
label="Ancho",
|
124 |
minimum=512,
|
125 |
maximum=1280,
|
126 |
step=8,
|
127 |
value=768,
|
128 |
)
|
129 |
height = gr.Slider(
|
130 |
+
label="Alto",
|
131 |
minimum=512,
|
132 |
maximum=1280,
|
133 |
step=8,
|
134 |
value=1024,
|
135 |
)
|
136 |
scales = gr.Slider(
|
137 |
+
label="Guía",
|
138 |
minimum=3.5,
|
139 |
maximum=7,
|
140 |
step=0.1,
|
141 |
value=3.5,
|
142 |
)
|
143 |
steps = gr.Slider(
|
144 |
+
label="Pasos",
|
145 |
minimum=1,
|
146 |
maximum=100,
|
147 |
step=1,
|
148 |
value=24,
|
149 |
)
|
150 |
seed = gr.Slider(
|
151 |
+
label="Semillas",
|
152 |
minimum=-1,
|
153 |
maximum=MAX_SEED,
|
154 |
step=1,
|
155 |
value=-1,
|
156 |
)
|
157 |
lora_add = gr.Textbox(
|
158 |
+
label="Agregar Flux LoRA",
|
159 |
+
info="Modelo de LoRA a agregar",
|
160 |
lines=1,
|
161 |
+
value="XLabs-AI/flux-RealismLora",
|
162 |
)
|
163 |
lora_word = gr.Textbox(
|
164 |
+
label="Palabra clave de LoRA",
|
165 |
+
info="Palabra clave para activar el modelo de LoRA",
|
166 |
lines=1,
|
167 |
value="",
|
168 |
)
|
169 |
+
upscale_factor = gr.Radio(
|
170 |
+
label="Factor de escalado",
|
171 |
+
choices=[2, 3, 4],
|
172 |
+
value=2,
|
173 |
+
)
|
|
|
|
|
|
|
|
|
174 |
|
175 |
gr.on(
|
176 |
triggers=[
|
|
|
186 |
height,
|
187 |
scales,
|
188 |
steps,
|
189 |
+
seed,
|
190 |
+
upscale_factor
|
191 |
],
|
192 |
outputs=[img, seed]
|
193 |
)
|