Update app.py
Browse files
app.py
CHANGED
|
@@ -28,18 +28,17 @@ pipe.to("cuda")
|
|
| 28 |
|
| 29 |
# Definição dos LoRA e Trigger Words
|
| 30 |
lora_models = {
|
| 31 |
-
"
|
| 32 |
"repo": "vcollos/vgn",
|
| 33 |
"weights": "vgn.safetensors",
|
| 34 |
"trigger_word": "" # Sem trigger word específica
|
| 35 |
},
|
| 36 |
-
"
|
| 37 |
"repo": "vcollos/Nanda",
|
| 38 |
"weights": "lora.safetensors",
|
| 39 |
-
"trigger_word": "A photo of
|
| 40 |
}
|
| 41 |
}
|
| 42 |
-
|
| 43 |
# Carrega os LoRAs
|
| 44 |
for name, details in lora_models.items():
|
| 45 |
try:
|
|
@@ -73,28 +72,6 @@ def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora
|
|
| 73 |
seed = random.randint(0, MAX_SEED)
|
| 74 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 75 |
|
| 76 |
-
# Moderação de texto
|
| 77 |
-
moderation_client = client_gradio("duchaba/Friendly_Text_Moderation")
|
| 78 |
-
result = moderation_client.predict(
|
| 79 |
-
msg=f"{prompt}",
|
| 80 |
-
safer=0.02,
|
| 81 |
-
api_name="/fetch_toxicity_level"
|
| 82 |
-
)
|
| 83 |
-
|
| 84 |
-
if float(json.loads(result[1])['sexual_minors']) > 0.03:
|
| 85 |
-
print('🔴 Conteúdo não permitido')
|
| 86 |
-
supabase.table("requests").insert({
|
| 87 |
-
"prompt": prompt,
|
| 88 |
-
"cfg_scale": cfg_scale,
|
| 89 |
-
"steps": steps,
|
| 90 |
-
"randomized_seed": randomize_seed,
|
| 91 |
-
"seed": seed,
|
| 92 |
-
"lora_scale_1": lora_scale_1,
|
| 93 |
-
"lora_scale_2": lora_scale_2,
|
| 94 |
-
"moderated": 'true'
|
| 95 |
-
}).execute()
|
| 96 |
-
raise gr.Error("🚫 Requisição não autorizada!")
|
| 97 |
-
|
| 98 |
# Aplica os adaptadores LoRA corretamente
|
| 99 |
pipe.set_adapters([selected_lora], adapter_weights=[1.0])
|
| 100 |
|
|
@@ -139,7 +116,8 @@ def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora
|
|
| 139 |
# Interface Gradio
|
| 140 |
gr_theme = os.getenv("THEME")
|
| 141 |
with gr.Blocks(theme=gr_theme) as app:
|
| 142 |
-
gr.Markdown("#
|
|
|
|
| 143 |
with gr.Row():
|
| 144 |
with gr.Column(scale=2):
|
| 145 |
prompt = gr.TextArea(label="Prompt", placeholder="Digite um prompt (máx 77 caracteres)", lines=3)
|
|
@@ -147,19 +125,26 @@ with gr.Blocks(theme=gr_theme) as app:
|
|
| 147 |
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, step=0.5, value=3.5)
|
| 148 |
steps = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=25)
|
| 149 |
width = gr.Slider(label="Width", minimum=256, maximum=1024, step=64, value=768)
|
| 150 |
-
height = gr.Slider(label="Height", minimum=256, maximum=1024, step=64, value=
|
| 151 |
randomize_seed = gr.Checkbox(False, label="Randomize seed")
|
| 152 |
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=556215326)
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
with gr.Column(scale=2):
|
| 155 |
result = gr.Image(label="Generated Image")
|
| 156 |
-
gr.Markdown("Gere imagens usando
|
| 157 |
|
|
|
|
| 158 |
generate_button.click(
|
| 159 |
run_lora,
|
| 160 |
-
inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale_1, lora_scale_2, selected_lora],
|
| 161 |
outputs=[result, seed],
|
| 162 |
)
|
| 163 |
|
| 164 |
app.queue()
|
| 165 |
-
app.launch(share=True)
|
|
|
|
| 28 |
|
| 29 |
# Definição dos LoRA e Trigger Words
|
| 30 |
lora_models = {
|
| 31 |
+
"vgn": {
|
| 32 |
"repo": "vcollos/vgn",
|
| 33 |
"weights": "vgn.safetensors",
|
| 34 |
"trigger_word": "" # Sem trigger word específica
|
| 35 |
},
|
| 36 |
+
"Nanda": {
|
| 37 |
"repo": "vcollos/Nanda",
|
| 38 |
"weights": "lora.safetensors",
|
| 39 |
+
"trigger_word": "A photo of Nanda, RAW photo, (hyperrealistic portrait:1.3) of a [man/woman], (detailed eyes:1.2), (skin texture:1.4), (natural lighting:1.1), (soft shadows:1.1), (intricate hair details:1.3), (film grain:0.8), (8k:1.2), (depth of field:1.1), (sharp focus:1.1),"
|
| 40 |
}
|
| 41 |
}
|
|
|
|
| 42 |
# Carrega os LoRAs
|
| 43 |
for name, details in lora_models.items():
|
| 44 |
try:
|
|
|
|
| 72 |
seed = random.randint(0, MAX_SEED)
|
| 73 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# Aplica os adaptadores LoRA corretamente
|
| 76 |
pipe.set_adapters([selected_lora], adapter_weights=[1.0])
|
| 77 |
|
|
|
|
| 116 |
# Interface Gradio
|
| 117 |
gr_theme = os.getenv("THEME")
|
| 118 |
with gr.Blocks(theme=gr_theme) as app:
|
| 119 |
+
gr.Markdown("# vgn Image Generator")
|
| 120 |
+
|
| 121 |
with gr.Row():
|
| 122 |
with gr.Column(scale=2):
|
| 123 |
prompt = gr.TextArea(label="Prompt", placeholder="Digite um prompt (máx 77 caracteres)", lines=3)
|
|
|
|
| 125 |
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, step=0.5, value=3.5)
|
| 126 |
steps = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=25)
|
| 127 |
width = gr.Slider(label="Width", minimum=256, maximum=1024, step=64, value=768)
|
| 128 |
+
height = gr.Slider(label="Height", minimum=256, maximum=1024, step=64, value=1024)
|
| 129 |
randomize_seed = gr.Checkbox(False, label="Randomize seed")
|
| 130 |
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=556215326)
|
| 131 |
+
|
| 132 |
+
# 🔥 Certificando que os sliders estão dentro do bloco correto
|
| 133 |
+
lora_scale_1 = gr.Slider(label="LoRA Scale (Vga)", minimum=0, maximum=1, step=0.01, value=0.5)
|
| 134 |
+
lora_scale_2 = gr.Slider(label="LoRA Scale (Nanda)", minimum=0, maximum=1, step=0.01, value=1)
|
| 135 |
+
|
| 136 |
+
selected_lora = gr.Dropdown(label="Selecionar LoRA", choices=["vgn", "Nanda"], value="Nanda")
|
| 137 |
+
|
| 138 |
with gr.Column(scale=2):
|
| 139 |
result = gr.Image(label="Generated Image")
|
| 140 |
+
gr.Markdown("Gere imagens usando vgn LoRA e um prompt de texto.")
|
| 141 |
|
| 142 |
+
# 🔥 Agora os sliders são usados corretamente
|
| 143 |
generate_button.click(
|
| 144 |
run_lora,
|
| 145 |
+
inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale_1, lora_scale_2, selected_lora],
|
| 146 |
outputs=[result, seed],
|
| 147 |
)
|
| 148 |
|
| 149 |
app.queue()
|
| 150 |
+
app.launch(share=True)
|