Flux_lora
#1
by
ameets21
- opened
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title: FLUX.Dev
|
3 |
-
emoji:
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: mit
|
|
|
1 |
---
|
2 |
+
title: FLUX.Dev LORA Serverless
|
3 |
+
emoji: 🔥
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.43.0
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: mit
|
app.py
CHANGED
@@ -13,21 +13,7 @@ API_TOKEN = os.getenv("HF_READ_TOKEN")
|
|
13 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
14 |
timeout = 100
|
15 |
|
16 |
-
|
17 |
-
<div style="text-align: center;">
|
18 |
-
<p>Enjoying the tool? Buy me a coffee and get exclusive prompt guides!</p>
|
19 |
-
<p><i>Instantly unlock helpful tips for creating better prompts!</i></p>
|
20 |
-
<div style="display: flex; justify-content: center;">
|
21 |
-
<a href="https://piczify.lemonsqueezy.com/buy/0f5206fa-68e8-42f6-9ca8-4f80c587c83e">
|
22 |
-
<img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png"
|
23 |
-
alt="Buy Me a Coffee"
|
24 |
-
style="height: 40px; width: auto; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); border-radius: 10px;">
|
25 |
-
</a>
|
26 |
-
</div>
|
27 |
-
</div>
|
28 |
-
"""
|
29 |
-
|
30 |
-
def query(lora_id, prompt, steps=28, cfg_scale=3.5, randomize_seed=True, seed=-1, width=1024, height=1024):
|
31 |
if prompt == "" or prompt == None:
|
32 |
return None
|
33 |
|
@@ -41,25 +27,21 @@ def query(lora_id, prompt, steps=28, cfg_scale=3.5, randomize_seed=True, seed=-1
|
|
41 |
API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN")])
|
42 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
43 |
|
44 |
-
|
45 |
-
|
46 |
|
47 |
prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
|
48 |
-
|
49 |
|
50 |
# If seed is -1, generate a random seed and use it
|
51 |
-
if
|
52 |
-
seed = random.randint(1,
|
53 |
|
54 |
payload = {
|
55 |
"inputs": prompt,
|
56 |
"steps": steps,
|
57 |
"cfg_scale": cfg_scale,
|
58 |
"seed": seed,
|
59 |
-
"parameters": {
|
60 |
-
"width": width, # Pass the width to the API
|
61 |
-
"height": height # Pass the height to the API
|
62 |
-
}
|
63 |
}
|
64 |
|
65 |
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
@@ -74,7 +56,7 @@ def query(lora_id, prompt, steps=28, cfg_scale=3.5, randomize_seed=True, seed=-1
|
|
74 |
image_bytes = response.content
|
75 |
image = Image.open(io.BytesIO(image_bytes))
|
76 |
print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
|
77 |
-
return image, seed
|
78 |
except Exception as e:
|
79 |
print(f"Error when trying to open the image: {e}")
|
80 |
return None
|
@@ -87,59 +69,43 @@ examples = [
|
|
87 |
]
|
88 |
|
89 |
css = """
|
90 |
-
#
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
.generate-btn {
|
95 |
-
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%) !important;
|
96 |
-
border: none !important;
|
97 |
-
color: white !important;
|
98 |
-
}
|
99 |
-
.generate-btn:hover {
|
100 |
-
transform: translateY(-2px);
|
101 |
-
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
102 |
}
|
103 |
"""
|
104 |
|
105 |
-
with gr.Blocks(css=css) as app:
|
106 |
gr.HTML("<center><h1>FLUX.1-Dev with LoRA support</h1></center>")
|
107 |
-
with gr.Column(elem_id="
|
108 |
with gr.Row():
|
109 |
-
with gr.Column():
|
110 |
with gr.Row():
|
111 |
-
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=
|
112 |
with gr.Row():
|
113 |
custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path (optional)", placeholder="multimodalart/vintage-ads-flux")
|
114 |
with gr.Row():
|
115 |
with gr.Accordion("Advanced Settings", open=False):
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
steps = gr.Slider(label="Sampling steps", value=28, minimum=1, maximum=100, step=1)
|
123 |
-
cfg = gr.Slider(label="CFG Scale", value=3.5, minimum=1, maximum=20, step=0.5)
|
124 |
-
# method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
with gr.Row():
|
133 |
-
seed_output = gr.Textbox(label="Seed Used", show_copy_button = True)
|
134 |
-
|
135 |
-
gr.Markdown(article_text)
|
136 |
-
with gr.Column():
|
137 |
-
gr.Examples(
|
138 |
-
examples = examples,
|
139 |
-
inputs = [text_prompt],
|
140 |
-
)
|
141 |
|
|
|
|
|
|
|
|
|
142 |
|
143 |
-
text_button.click(query, inputs=[custom_lora, text_prompt, steps, cfg,
|
144 |
|
145 |
app.launch(show_api=False, share=False)
|
|
|
13 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
14 |
timeout = 100
|
15 |
|
16 |
+
def query(lora_id, prompt, is_negative=False, steps=28, cfg_scale=3.5, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
if prompt == "" or prompt == None:
|
18 |
return None
|
19 |
|
|
|
27 |
API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN")])
|
28 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
29 |
|
30 |
+
prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
31 |
+
print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
|
32 |
|
33 |
prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
|
34 |
+
print(f'\033[1mGeneration {key}:\033[0m {prompt}')
|
35 |
|
36 |
# If seed is -1, generate a random seed and use it
|
37 |
+
if seed == -1:
|
38 |
+
seed = random.randint(1, 1000000000)
|
39 |
|
40 |
payload = {
|
41 |
"inputs": prompt,
|
42 |
"steps": steps,
|
43 |
"cfg_scale": cfg_scale,
|
44 |
"seed": seed,
|
|
|
|
|
|
|
|
|
45 |
}
|
46 |
|
47 |
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
|
|
56 |
image_bytes = response.content
|
57 |
image = Image.open(io.BytesIO(image_bytes))
|
58 |
print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
|
59 |
+
return image, seed
|
60 |
except Exception as e:
|
61 |
print(f"Error when trying to open the image: {e}")
|
62 |
return None
|
|
|
69 |
]
|
70 |
|
71 |
css = """
|
72 |
+
#app-container {
|
73 |
+
max-width: 600px;
|
74 |
+
margin-left: auto;
|
75 |
+
margin-right: auto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
}
|
77 |
"""
|
78 |
|
79 |
+
with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
|
80 |
gr.HTML("<center><h1>FLUX.1-Dev with LoRA support</h1></center>")
|
81 |
+
with gr.Column(elem_id="app-container"):
|
82 |
with gr.Row():
|
83 |
+
with gr.Column(elem_id="prompt-container"):
|
84 |
with gr.Row():
|
85 |
+
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input")
|
86 |
with gr.Row():
|
87 |
custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path (optional)", placeholder="multimodalart/vintage-ads-flux")
|
88 |
with gr.Row():
|
89 |
with gr.Accordion("Advanced Settings", open=False):
|
90 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", value="(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, misspellings, typos", lines=3, elem_id="negative-prompt-text-input")
|
91 |
+
steps = gr.Slider(label="Sampling steps", value=28, minimum=1, maximum=100, step=1)
|
92 |
+
cfg = gr.Slider(label="CFG Scale", value=3.5, minimum=1, maximum=20, step=0.5)
|
93 |
+
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
94 |
+
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
95 |
+
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
|
|
|
|
|
|
96 |
|
97 |
+
with gr.Row():
|
98 |
+
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
99 |
+
with gr.Row():
|
100 |
+
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
101 |
+
with gr.Row():
|
102 |
+
seed_output = gr.Textbox(label="Seed Used", show_copy_button = True, elem_id="seed-output")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
+
gr.Examples(
|
105 |
+
examples = examples,
|
106 |
+
inputs = [text_prompt],
|
107 |
+
)
|
108 |
|
109 |
+
text_button.click(query, inputs=[custom_lora, text_prompt, negative_prompt, steps, cfg, method, seed, strength], outputs=[image_output,seed_output])
|
110 |
|
111 |
app.launch(show_api=False, share=False)
|