Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,14 @@ import io
|
|
4 |
import random
|
5 |
import os
|
6 |
import time
|
7 |
-
import
|
|
|
|
|
|
|
8 |
from PIL import Image
|
9 |
from deep_translator import GoogleTranslator
|
10 |
import json
|
|
|
11 |
from fastapi import FastAPI
|
12 |
|
13 |
app = FastAPI()
|
@@ -52,8 +56,11 @@ timeout = 100
|
|
52 |
|
53 |
def flip_image(x):
|
54 |
return np.fliplr(x)
|
55 |
-
|
56 |
-
def
|
|
|
|
|
|
|
57 |
if prompt == "" or prompt == None:
|
58 |
return None
|
59 |
|
@@ -66,7 +73,7 @@ def query(lora_id, prompt, is_negative=False, steps=28, cfg_scale=3.5, sampler=
|
|
66 |
|
67 |
API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN")])
|
68 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
69 |
-
|
70 |
# prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
71 |
# print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
|
72 |
prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
@@ -109,27 +116,22 @@ def query(lora_id, prompt, is_negative=False, steps=28, cfg_scale=3.5, sampler=
|
|
109 |
except Exception as e:
|
110 |
print(f"Error when trying to open the image: {e}")
|
111 |
return None
|
112 |
-
|
113 |
-
def clear():
|
114 |
-
return None
|
115 |
-
|
116 |
examples = [
|
117 |
"a beautiful woman with blonde hair and blue eyes",
|
118 |
"a beautiful woman with brown hair and grey eyes",
|
119 |
"a beautiful woman with black hair and brown eyes",
|
120 |
]
|
121 |
|
122 |
-
|
123 |
css = """
|
124 |
#app-container {
|
125 |
max-width: 930px;
|
126 |
margin-left: auto;
|
127 |
margin-right: auto;
|
128 |
-
|
129 |
}
|
|
|
130 |
|
131 |
"""
|
132 |
-
|
133 |
with gr.Blocks(theme=theme, css=css, elem_id="app-container") as app:
|
134 |
gr.HTML("<center><h6>🎨 FLUX.1-Dev with LoRA 🇬🇧</h6></center>")
|
135 |
with gr.Tab("Text to Image"):
|
@@ -139,63 +141,58 @@ with gr.Blocks(theme=theme, css=css, elem_id="app-container") as app:
|
|
139 |
with gr.Row():
|
140 |
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input")
|
141 |
with gr.Row():
|
142 |
-
with gr.Accordion(
|
143 |
gr.Markdown("""
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
|
161 |
with gr.Row():
|
162 |
-
custom_lora = gr.Dropdown([" ", "jwu114/lora-sdxl-realistic", "issaccyj/lora-sdxl-cyberpunk", "hugovntr/flux-schnell-realism", "fofr/sdxl-deep-down", "KappaNeuro/surreal-harmony", "ntc-ai/SDXL-LoRA-slider.extremely-detailed", "prithivMLmods/Canopus-LoRA-Flux-FaceRealism", "KappaNeuro/dark-fantasy", "artificialguybr/analogredmond", "KappaNeuro/jules-bastien-lepage-style", "KappaNeuro/john-singer-sargent-style", "KappaNeuro/alphonse-mucha-style", "ntc-ai/SDXL-LoRA-slider.ultra-realistic-illustration", "ntc-ai/SDXL-LoRA-slider.eye-catching", "KappaNeuro/john-constable-style", "dvyio/flux-lora-film-noir", "
|
163 |
with gr.Row():
|
164 |
with gr.Accordion("⚙️ Advanced Settings", open=False, elem_id="settings-container"):
|
165 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", value=" bad anatomy, bad hands, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, worst face, three crus, extra crus, fused crus, worst feet, three feet, fused feet, fused thigh, three thigh, fused thigh, extra thigh, worst thigh, missing fingers, extra fingers, ugly fingers, long fingers, horn, extra eyes, huge eyes, 2girl, amputation, disconnected limbs, cartoon, cg, 3d, unreal, animate", lines=3, elem_id="negative-prompt-text-input")
|
166 |
with gr.Row():
|
167 |
-
width = gr.Slider(label="Width", value=
|
168 |
-
height = gr.Slider(label="Height", value=
|
169 |
steps = gr.Slider(label="Sampling steps", value=50, minimum=1, maximum=100, step=1)
|
170 |
cfg = gr.Slider(label="CFG Scale", value=3.5, minimum=1, maximum=20, step=0.5)
|
171 |
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "DEIS", "LMS", "DPM Adaptive", "DPM++ 2M", "DPM++ S", "DPM++ SDE", "DDPM", "DPM Fast", "Euler", "Euler CFG PP", "Euler a", "Euler+beta", "Heun", "Heun PP2", "DDIM", "PLMS", "UniPC", "UniPC BH2"])
|
172 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
173 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
174 |
-
|
175 |
with gr.Row():
|
176 |
with gr.Accordion("🫘Seed", open=False):
|
177 |
seed_output = gr.Textbox(label="Seed Used", show_copy_button = True, elem_id="seed-output")
|
178 |
|
179 |
with gr.Row():
|
180 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
181 |
-
clr_button =gr.Button("Clear
|
182 |
clr_button.click(lambda: gr.Textbox(value=""), None, text_prompt)
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
clear_btn = gr.Button(value="Clear Image",variant="primary", elem_id="clear_button")
|
190 |
-
clear_btn.click(clear, inputs=[ ], outputs=[image_output])
|
191 |
-
|
192 |
-
|
193 |
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
text_button.click(query, inputs=[custom_lora, text_prompt, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=[image_output, seed_output])
|
200 |
|
201 |
with gr.Tab("Flip Image"):
|
@@ -205,6 +202,7 @@ with gr.Blocks(theme=theme, css=css, elem_id="app-container") as app:
|
|
205 |
with gr.Row():
|
206 |
image_button = gr.Button("Run", variant='primary')
|
207 |
image_button.click(flip_image, inputs=image_input, outputs=image_output)
|
208 |
-
|
209 |
-
if __name__ == "__main__":
|
210 |
-
|
|
|
|
4 |
import random
|
5 |
import os
|
6 |
import time
|
7 |
+
import numpy as np
|
8 |
+
import subprocess
|
9 |
+
import torch
|
10 |
+
from transformers import AutoProcessor, AutoModelForCausalLM
|
11 |
from PIL import Image
|
12 |
from deep_translator import GoogleTranslator
|
13 |
import json
|
14 |
+
from datetime import datetime
|
15 |
from fastapi import FastAPI
|
16 |
|
17 |
app = FastAPI()
|
|
|
56 |
|
57 |
def flip_image(x):
|
58 |
return np.fliplr(x)
|
59 |
+
|
60 |
+
def clear():
|
61 |
+
return None
|
62 |
+
|
63 |
+
def query(lora_id, prompt, is_negative=False, steps=28, cfg_scale=3.5, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, width=896, height=1152):
|
64 |
if prompt == "" or prompt == None:
|
65 |
return None
|
66 |
|
|
|
73 |
|
74 |
API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN")])
|
75 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
76 |
+
|
77 |
# prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
78 |
# print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
|
79 |
prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
|
|
116 |
except Exception as e:
|
117 |
print(f"Error when trying to open the image: {e}")
|
118 |
return None
|
119 |
+
|
|
|
|
|
|
|
120 |
examples = [
|
121 |
"a beautiful woman with blonde hair and blue eyes",
|
122 |
"a beautiful woman with brown hair and grey eyes",
|
123 |
"a beautiful woman with black hair and brown eyes",
|
124 |
]
|
125 |
|
|
|
126 |
css = """
|
127 |
#app-container {
|
128 |
max-width: 930px;
|
129 |
margin-left: auto;
|
130 |
margin-right: auto;
|
|
|
131 |
}
|
132 |
+
".gradio-container {background: url('file=abstract.jpg')}
|
133 |
|
134 |
"""
|
|
|
135 |
with gr.Blocks(theme=theme, css=css, elem_id="app-container") as app:
|
136 |
gr.HTML("<center><h6>🎨 FLUX.1-Dev with LoRA 🇬🇧</h6></center>")
|
137 |
with gr.Tab("Text to Image"):
|
|
|
141 |
with gr.Row():
|
142 |
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input")
|
143 |
with gr.Row():
|
144 |
+
with gr.Accordion("Lora trigger words", open=False):
|
145 |
gr.Markdown("""
|
146 |
+
### 🎨 Lora trigger words:
|
147 |
+
- **sdxl-realistic**: szn style
|
148 |
+
- **stylesdxl-cyberpunk**: szn style
|
149 |
+
- **surreal-harmony**: Surreal Harmony
|
150 |
+
- **extremely-detailed**: extremely detailed
|
151 |
+
- **dark-fantasy**: Dark Fantasy
|
152 |
+
- **analogredmond**: AnalogRedmAF
|
153 |
+
- **jules-bastien-lepage-style**: Jules Bastien Lepage Style
|
154 |
+
- **john-singer-sargent-style**: John Singer Sargent Style
|
155 |
+
- **alphonse-mucha-style**: Alphonse Mucha Style
|
156 |
+
- **ultra-realistic-illustration**: ultra realistic illustration
|
157 |
+
- **eye-catching**: eye-catching
|
158 |
+
- **john-constable-style**: John Constable Style
|
159 |
+
- **film-noir**: in the style of FLMNR
|
160 |
+
- **director-sofia-coppola-style**: Director Sofia Coppola Style
|
161 |
+
""")
|
162 |
|
163 |
with gr.Row():
|
164 |
+
custom_lora = gr.Dropdown([" ", "jwu114/lora-sdxl-realistic", "issaccyj/lora-sdxl-cyberpunk", "hugovntr/flux-schnell-realism", "fofr/sdxl-deep-down", "KappaNeuro/surreal-harmony", "ntc-ai/SDXL-LoRA-slider.extremely-detailed", "prithivMLmods/Canopus-LoRA-Flux-FaceRealism", "KappaNeuro/dark-fantasy", "artificialguybr/analogredmond", "KappaNeuro/jules-bastien-lepage-style", "KappaNeuro/john-singer-sargent-style", "KappaNeuro/alphonse-mucha-style", "ntc-ai/SDXL-LoRA-slider.ultra-realistic-illustration", "ntc-ai/SDXL-LoRA-slider.eye-catching", "KappaNeuro/john-constable-style", "dvyio/flux-lora-film-noir", "KappaNeuro/director-sofia-coppola-style"], label="Custom LoRA",)
|
165 |
with gr.Row():
|
166 |
with gr.Accordion("⚙️ Advanced Settings", open=False, elem_id="settings-container"):
|
167 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", value=" bad anatomy, bad hands, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, worst face, three crus, extra crus, fused crus, worst feet, three feet, fused feet, fused thigh, three thigh, fused thigh, extra thigh, worst thigh, missing fingers, extra fingers, ugly fingers, long fingers, horn, extra eyes, huge eyes, 2girl, amputation, disconnected limbs, cartoon, cg, 3d, unreal, animate", lines=3, elem_id="negative-prompt-text-input")
|
168 |
with gr.Row():
|
169 |
+
width = gr.Slider(label="Width", value=896, minimum=64, maximum=1216, step=32)
|
170 |
+
height = gr.Slider(label="Height", value=1152, minimum=64, maximum=1216, step=32)
|
171 |
steps = gr.Slider(label="Sampling steps", value=50, minimum=1, maximum=100, step=1)
|
172 |
cfg = gr.Slider(label="CFG Scale", value=3.5, minimum=1, maximum=20, step=0.5)
|
173 |
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "DEIS", "LMS", "DPM Adaptive", "DPM++ 2M", "DPM++ S", "DPM++ SDE", "DDPM", "DPM Fast", "Euler", "Euler CFG PP", "Euler a", "Euler+beta", "Heun", "Heun PP2", "DDIM", "PLMS", "UniPC", "UniPC BH2"])
|
174 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
175 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
|
|
176 |
with gr.Row():
|
177 |
with gr.Accordion("🫘Seed", open=False):
|
178 |
seed_output = gr.Textbox(label="Seed Used", show_copy_button = True, elem_id="seed-output")
|
179 |
|
180 |
with gr.Row():
|
181 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
182 |
+
clr_button =gr.Button("Clear Prompt",variant="primary", elem_id="clear_button")
|
183 |
clr_button.click(lambda: gr.Textbox(value=""), None, text_prompt)
|
184 |
+
|
185 |
+
with gr.Row():
|
186 |
+
image_output = gr.Image(type="pil", label="Image Output", format="png", elem_id="gallery")
|
187 |
+
with gr.Row():
|
188 |
+
clear_btn = gr.Button(value="Clear Image", variant="primary", elem_id="clear_button")
|
189 |
+
clear_btn.click(clear, inputs=[], outputs=[image_output])
|
|
|
|
|
|
|
|
|
190 |
|
191 |
+
gr.Examples(
|
192 |
+
examples = examples,
|
193 |
+
inputs = [text_prompt],
|
194 |
+
)
|
195 |
+
|
196 |
text_button.click(query, inputs=[custom_lora, text_prompt, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=[image_output, seed_output])
|
197 |
|
198 |
with gr.Tab("Flip Image"):
|
|
|
202 |
with gr.Row():
|
203 |
image_button = gr.Button("Run", variant='primary')
|
204 |
image_button.click(flip_image, inputs=image_input, outputs=image_output)
|
205 |
+
|
206 |
+
if __name__ == "__main__":
|
207 |
+
app.launch(show_api=False, share=False)
|
208 |
+
|