Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,7 +44,12 @@ def generate_character_description(character_prompt, system_message = """
|
|
| 44 |
return result
|
| 45 |
except Exception as e:
|
| 46 |
return f"Error generating description: {str(e)}"
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
# Function to generate image
|
| 49 |
async def generate_image(prompt, model, lora_word, width, height, scales, steps, seed):
|
| 50 |
try:
|
|
@@ -53,7 +58,7 @@ async def generate_image(prompt, model, lora_word, width, height, scales, steps,
|
|
| 53 |
seed = int(seed)
|
| 54 |
|
| 55 |
print(f"[-] Menerjemahkan prompt: {prompt}")
|
| 56 |
-
|
| 57 |
|
| 58 |
print(f"[-] Generating image with prompt: {text}, model: {model}")
|
| 59 |
client = AsyncInferenceClient()
|
|
@@ -66,18 +71,18 @@ async def generate_image(prompt, model, lora_word, width, height, scales, steps,
|
|
| 66 |
# Function to upscale image
|
| 67 |
def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
| 68 |
try:
|
| 69 |
-
print(f"[-]
|
| 70 |
client = Client("finegrain/finegrain-image-enhancer", hf_token=HF_TOKEN_UPSCALER)
|
| 71 |
result = client.predict(
|
| 72 |
input_image=handle_file(img_path),
|
| 73 |
prompt=prompt,
|
| 74 |
negative_prompt="worst quality, low quality, normal quality",
|
| 75 |
upscale_factor=upscale_factor,
|
| 76 |
-
controlnet_scale=0.
|
| 77 |
controlnet_decay=1,
|
| 78 |
condition_scale=6,
|
| 79 |
-
denoise_strength=0.
|
| 80 |
-
num_inference_steps=
|
| 81 |
solver="DDIM",
|
| 82 |
api_name="/process"
|
| 83 |
)
|
|
@@ -112,7 +117,7 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
| 112 |
print(f"[-] Proses upscaling selesai. Gambar tersimpan di: {upscale_image_path}")
|
| 113 |
return [image_path, upscale_image_path] # Return both images
|
| 114 |
else:
|
| 115 |
-
print("[-] Upscaling
|
| 116 |
|
| 117 |
return [image_path]
|
| 118 |
|
|
@@ -162,52 +167,49 @@ with gr.Blocks(css=css, theme=IndonesiaTheme()) as WallpaperFluxMaker:
|
|
| 162 |
# Column 1: Input prompt, LoRA, and base model
|
| 163 |
with gr.Column(scale=1, elem_id="col-left"):
|
| 164 |
prompt = gr.Textbox(
|
| 165 |
-
label="π
|
| 166 |
-
placeholder="
|
| 167 |
elem_id="textbox-prompt"
|
| 168 |
)
|
| 169 |
|
| 170 |
basemodel_choice = gr.Dropdown(
|
| 171 |
-
label="πΌοΈ
|
| 172 |
choices=[
|
| 173 |
-
"black-forest-labs/FLUX.1-schnell",
|
| 174 |
-
"black-forest-labs/FLUX.1-
|
| 175 |
-
"
|
| 176 |
-
"dataautogpt3/FLUX-SyntheticAnime",
|
| 177 |
-
"Shakker-Labs/FLUX.1-dev-LoRA-AntiBlur"
|
| 178 |
"Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro",
|
| 179 |
"Shakker-Labs/FLUX.1-dev-LoRA-add-details",
|
| 180 |
-
"city96/FLUX.1-
|
| 181 |
],
|
| 182 |
value="black-forest-labs/FLUX.1-schnell"
|
| 183 |
)
|
| 184 |
|
| 185 |
lora_model_choice = gr.Dropdown(
|
| 186 |
-
label="π¨
|
| 187 |
choices=[
|
| 188 |
"Shakker-Labs/FLUX.1-dev-LoRA-add-details",
|
| 189 |
"XLabs-AI/flux-RealismLora",
|
| 190 |
-
"enhanceaiteam/Flux-uncensored"
|
| 191 |
-
|
| 192 |
-
]+loaded_loras,
|
| 193 |
value="XLabs-AI/flux-RealismLora"
|
| 194 |
)
|
| 195 |
|
| 196 |
-
process_lora =gr.Checkbox(label="π¨
|
| 197 |
-
process_upscale = gr.Checkbox(label="π
|
| 198 |
-
upscale_factor = gr.Radio(label="π
|
| 199 |
|
| 200 |
# Column 2: Advanced options (always open)
|
| 201 |
with gr.Column(scale=1, elem_id="col-right"):
|
| 202 |
-
with gr.Accordion(label="βοΈ
|
| 203 |
-
width = gr.Slider(label="
|
| 204 |
-
height = gr.Slider(label="
|
| 205 |
-
scales = gr.Slider(label="
|
| 206 |
-
steps = gr.Slider(label="
|
| 207 |
seed = gr.Number(label="Seed", value=-1)
|
| 208 |
|
| 209 |
# Button to generate image
|
| 210 |
-
btn = gr.Button("π
|
| 211 |
|
| 212 |
# Running the `gen` function when "Generate" button is pressed
|
| 213 |
btn.click(fn=gen, inputs=[
|
|
@@ -215,4 +217,4 @@ with gr.Blocks(css=css, theme=IndonesiaTheme()) as WallpaperFluxMaker:
|
|
| 215 |
], outputs=output_res)
|
| 216 |
|
| 217 |
# Launching the Gradio app
|
| 218 |
-
WallpaperFluxMaker.queue(api_open=False).launch(show_api=
|
|
|
|
| 44 |
return result
|
| 45 |
except Exception as e:
|
| 46 |
return f"Error generating description: {str(e)}"
|
| 47 |
+
|
| 48 |
+
# Function to enable LoRA if selected
|
| 49 |
+
def enable_lora(lora_add, basemodel):
|
| 50 |
+
print(f"[-] Menentukan model: LoRA {'diaktifkan' if lora_add else 'tidak diaktifkan'}, model dasar: {basemodel}")
|
| 51 |
+
return basemodel if not lora_add else lora_add
|
| 52 |
+
|
| 53 |
# Function to generate image
|
| 54 |
async def generate_image(prompt, model, lora_word, width, height, scales, steps, seed):
|
| 55 |
try:
|
|
|
|
| 58 |
seed = int(seed)
|
| 59 |
|
| 60 |
print(f"[-] Menerjemahkan prompt: {prompt}")
|
| 61 |
+
text = str(Translator().translate(prompt, 'English')) + "," + lora_word
|
| 62 |
|
| 63 |
print(f"[-] Generating image with prompt: {text}, model: {model}")
|
| 64 |
client = AsyncInferenceClient()
|
|
|
|
| 71 |
# Function to upscale image
|
| 72 |
def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
| 73 |
try:
|
| 74 |
+
print(f"[-] Memulai proses upscaling dengan faktor {upscale_factor} untuk gambar {img_path}")
|
| 75 |
client = Client("finegrain/finegrain-image-enhancer", hf_token=HF_TOKEN_UPSCALER)
|
| 76 |
result = client.predict(
|
| 77 |
input_image=handle_file(img_path),
|
| 78 |
prompt=prompt,
|
| 79 |
negative_prompt="worst quality, low quality, normal quality",
|
| 80 |
upscale_factor=upscale_factor,
|
| 81 |
+
controlnet_scale=0.6,
|
| 82 |
controlnet_decay=1,
|
| 83 |
condition_scale=6,
|
| 84 |
+
denoise_strength=0.35,
|
| 85 |
+
num_inference_steps=18,
|
| 86 |
solver="DDIM",
|
| 87 |
api_name="/process"
|
| 88 |
)
|
|
|
|
| 117 |
print(f"[-] Proses upscaling selesai. Gambar tersimpan di: {upscale_image_path}")
|
| 118 |
return [image_path, upscale_image_path] # Return both images
|
| 119 |
else:
|
| 120 |
+
print("[-] Upscaling gagal, jalur gambar upscale tidak ditemukan.")
|
| 121 |
|
| 122 |
return [image_path]
|
| 123 |
|
|
|
|
| 167 |
# Column 1: Input prompt, LoRA, and base model
|
| 168 |
with gr.Column(scale=1, elem_id="col-left"):
|
| 169 |
prompt = gr.Textbox(
|
| 170 |
+
label="π Deskripsi Gambar",
|
| 171 |
+
placeholder="Tuliskan prompt Anda dalam bahasa apapun, yang akan langsung diterjemahkan ke bahasa Inggris.",
|
| 172 |
elem_id="textbox-prompt"
|
| 173 |
)
|
| 174 |
|
| 175 |
basemodel_choice = gr.Dropdown(
|
| 176 |
+
label="πΌοΈ Pilih Model",
|
| 177 |
choices=[
|
| 178 |
+
"black-forest-labs/FLUX.1-schnell",
|
| 179 |
+
"black-forest-labs/FLUX.1-DEV",
|
| 180 |
+
"enhanceaiteam/Flux-uncensored",
|
|
|
|
|
|
|
| 181 |
"Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro",
|
| 182 |
"Shakker-Labs/FLUX.1-dev-LoRA-add-details",
|
| 183 |
+
"city96/FLUX.1-dev-gguf"
|
| 184 |
],
|
| 185 |
value="black-forest-labs/FLUX.1-schnell"
|
| 186 |
)
|
| 187 |
|
| 188 |
lora_model_choice = gr.Dropdown(
|
| 189 |
+
label="π¨ Pilih LoRA",
|
| 190 |
choices=[
|
| 191 |
"Shakker-Labs/FLUX.1-dev-LoRA-add-details",
|
| 192 |
"XLabs-AI/flux-RealismLora",
|
| 193 |
+
"enhanceaiteam/Flux-uncensored"
|
| 194 |
+
],
|
|
|
|
| 195 |
value="XLabs-AI/flux-RealismLora"
|
| 196 |
)
|
| 197 |
|
| 198 |
+
process_lora = gr.Checkbox(label="π¨ Aktifkan LoRA")
|
| 199 |
+
process_upscale = gr.Checkbox(label="π Aktifkan Peningkatan Resolusi")
|
| 200 |
+
upscale_factor = gr.Radio(label="π Faktor Peningkatan Resolusi", choices=[2, 4, 8], value=2)
|
| 201 |
|
| 202 |
# Column 2: Advanced options (always open)
|
| 203 |
with gr.Column(scale=1, elem_id="col-right"):
|
| 204 |
+
with gr.Accordion(label="βοΈ Opsi Lanjutan", open=True):
|
| 205 |
+
width = gr.Slider(label="Lebar", minimum=512, maximum=1280, step=8, value=1280)
|
| 206 |
+
height = gr.Slider(label="Tinggi", minimum=512, maximum=1280, step=8, value=768)
|
| 207 |
+
scales = gr.Slider(label="Skala", minimum=1, maximum=20, step=1, value=8)
|
| 208 |
+
steps = gr.Slider(label="Langkah", minimum=1, maximum=100, step=1, value=8)
|
| 209 |
seed = gr.Number(label="Seed", value=-1)
|
| 210 |
|
| 211 |
# Button to generate image
|
| 212 |
+
btn = gr.Button("π Buat Gambar", elem_id="generate-btn")
|
| 213 |
|
| 214 |
# Running the `gen` function when "Generate" button is pressed
|
| 215 |
btn.click(fn=gen, inputs=[
|
|
|
|
| 217 |
], outputs=output_res)
|
| 218 |
|
| 219 |
# Launching the Gradio app
|
| 220 |
+
WallpaperFluxMaker.queue(api_open=False).launch(show_api=False)
|