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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
App 2: Basic Adjustments
|
| 3 |
+
Micro-app para ajustes básicos de imagem: brilho, contraste, saturação, nitidez
|
| 4 |
+
"""
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from PIL import Image, ImageEnhance, ImageOps
|
| 7 |
+
import tempfile
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
import numpy as np
|
| 11 |
+
from typing import Optional, Tuple
|
| 12 |
+
|
| 13 |
+
class BasicAdjustmentsApp:
|
| 14 |
+
"""Micro-app dedicado apenas a ajustes básicos de imagem"""
|
| 15 |
+
|
| 16 |
+
def __init__(self):
|
| 17 |
+
self.supported_formats = ['.jpg', '.jpeg', '.png', '.bmp', '.webp']
|
| 18 |
+
|
| 19 |
+
def load_image(self, file_path: str) -> Tuple[Optional[Image.Image], str]:
|
| 20 |
+
"""Carrega imagem para edição"""
|
| 21 |
+
try:
|
| 22 |
+
if not file_path:
|
| 23 |
+
return None, "⚠️ Por favor, selecione uma imagem"
|
| 24 |
+
|
| 25 |
+
if not os.path.exists(file_path):
|
| 26 |
+
return None, "❌ Arquivo não encontrado"
|
| 27 |
+
|
| 28 |
+
ext = Path(file_path).suffix.lower()
|
| 29 |
+
if ext not in self.supported_formats:
|
| 30 |
+
return None, f"❌ Formato não suportado: {ext}"
|
| 31 |
+
|
| 32 |
+
img = Image.open(file_path)
|
| 33 |
+
|
| 34 |
+
# Converter para RGB para garantir compatibilidade
|
| 35 |
+
if img.mode != 'RGB':
|
| 36 |
+
img = img.convert('RGB')
|
| 37 |
+
|
| 38 |
+
info = f"✅ Imagem carregada: {img.width}x{img.height}px"
|
| 39 |
+
return img, info
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return None, f"❌ Erro: {str(e)}"
|
| 43 |
+
|
| 44 |
+
def apply_adjustments(self,
|
| 45 |
+
image: Image.Image,
|
| 46 |
+
brightness: float,
|
| 47 |
+
contrast: float,
|
| 48 |
+
saturation: float,
|
| 49 |
+
sharpness: float,
|
| 50 |
+
auto_contrast: bool = False) -> Image.Image:
|
| 51 |
+
"""
|
| 52 |
+
Aplica todos os ajustes básicos à imagem
|
| 53 |
+
|
| 54 |
+
Args:
|
| 55 |
+
image: Imagem PIL original
|
| 56 |
+
brightness: Fator de brilho (0.0 a 2.0)
|
| 57 |
+
contrast: Fator de contraste (0.0 a 2.0)
|
| 58 |
+
saturation: Fator de saturação (0.0 a 2.0)
|
| 59 |
+
sharpness: Fator de nitidez (0.0 a 2.0)
|
| 60 |
+
auto_contrast: Aplicar contraste automático
|
| 61 |
+
|
| 62 |
+
Returns:
|
| 63 |
+
Imagem ajustada
|
| 64 |
+
"""
|
| 65 |
+
try:
|
| 66 |
+
# Fazer uma cópia para não modificar a original
|
| 67 |
+
adjusted = image.copy()
|
| 68 |
+
|
| 69 |
+
# Aplicar ajustes na ordem correta
|
| 70 |
+
if auto_contrast:
|
| 71 |
+
adjusted = ImageOps.autocontrast(adjusted, cutoff=2)
|
| 72 |
+
|
| 73 |
+
# Brilho
|
| 74 |
+
if brightness != 1.0:
|
| 75 |
+
enhancer = ImageEnhance.Brightness(adjusted)
|
| 76 |
+
adjusted = enhancer.enhance(brightness)
|
| 77 |
+
|
| 78 |
+
# Contraste
|
| 79 |
+
if contrast != 1.0:
|
| 80 |
+
enhancer = ImageEnhance.Contrast(adjusted)
|
| 81 |
+
adjusted = enhancer.enhance(contrast)
|
| 82 |
+
|
| 83 |
+
# Saturação (Color)
|
| 84 |
+
if saturation != 1.0:
|
| 85 |
+
enhancer = ImageEnhance.Color(adjusted)
|
| 86 |
+
adjusted = enhancer.enhance(saturation)
|
| 87 |
+
|
| 88 |
+
# Nitidez
|
| 89 |
+
if sharpness != 1.0:
|
| 90 |
+
enhancer = ImageEnhance.Sharpness(adjusted)
|
| 91 |
+
adjusted = enhancer.enhance(sharpness)
|
| 92 |
+
|
| 93 |
+
return adjusted
|
| 94 |
+
|
| 95 |
+
except Exception as e:
|
| 96 |
+
print(f"Erro nos ajustes: {str(e)}")
|
| 97 |
+
return image
|
| 98 |
+
|
| 99 |
+
def reset_adjustments(self) -> dict:
|
| 100 |
+
"""Reseta todos os ajustes para valores padrão"""
|
| 101 |
+
return {
|
| 102 |
+
'brightness': 1.0,
|
| 103 |
+
'contrast': 1.0,
|
| 104 |
+
'saturation': 1.0,
|
| 105 |
+
'sharpness': 1.0,
|
| 106 |
+
'auto_contrast': False
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
def export_image(self, image: Image.Image, format: str = "PNG") -> Optional[str]:
|
| 110 |
+
"""Exporta imagem ajustada"""
|
| 111 |
+
try:
|
| 112 |
+
format_lower = format.lower()
|
| 113 |
+
suffix = f".{format_lower}"
|
| 114 |
+
|
| 115 |
+
save_args = {'format': format}
|
| 116 |
+
if format_lower == 'jpeg':
|
| 117 |
+
save_args['quality'] = 95
|
| 118 |
+
save_args['optimize'] = True
|
| 119 |
+
|
| 120 |
+
with tempfile.NamedTemporaryFile(
|
| 121 |
+
delete=False,
|
| 122 |
+
suffix=suffix,
|
| 123 |
+
prefix='adjusted_'
|
| 124 |
+
) as tmp_file:
|
| 125 |
+
image.save(tmp_file.name, **save_args)
|
| 126 |
+
return tmp_file.name
|
| 127 |
+
|
| 128 |
+
except Exception as e:
|
| 129 |
+
print(f"Erro na exportação: {str(e)}")
|
| 130 |
+
return None
|
| 131 |
+
|
| 132 |
+
def get_preset(self, preset_name: str) -> dict:
|
| 133 |
+
"""Retorna valores pré-definidos para ajustes rápidos"""
|
| 134 |
+
presets = {
|
| 135 |
+
'vibrant': {'brightness': 1.1, 'contrast': 1.2, 'saturation': 1.3, 'sharpness': 1.1},
|
| 136 |
+
'soft': {'brightness': 1.05, 'contrast': 0.9, 'saturation': 0.8, 'sharpness': 0.9},
|
| 137 |
+
'dramatic': {'brightness': 0.9, 'contrast': 1.4, 'saturation': 0.9, 'sharpness': 1.3},
|
| 138 |
+
'retro': {'brightness': 1.0, 'contrast': 1.1, 'saturation': 0.6, 'sharpness': 1.0},
|
| 139 |
+
'black_white': {'brightness': 1.0, 'contrast': 1.2, 'saturation': 0.0, 'sharpness': 1.1}
|
| 140 |
+
}
|
| 141 |
+
return presets.get(preset_name, self.reset_adjustments())
|
| 142 |
+
|
| 143 |
+
# Criar instância do app
|
| 144 |
+
adjustment_app = BasicAdjustmentsApp()
|
| 145 |
+
|
| 146 |
+
# Interface Gradio
|
| 147 |
+
def create_interface():
|
| 148 |
+
"""Cria interface com controles bem organizados"""
|
| 149 |
+
|
| 150 |
+
with gr.Blocks(
|
| 151 |
+
title="✨ Basic Adjustments",
|
| 152 |
+
theme=gr.themes.Soft(),
|
| 153 |
+
css="""
|
| 154 |
+
.slider-container {
|
| 155 |
+
padding: 10px;
|
| 156 |
+
border-radius: 8px;
|
| 157 |
+
background: #f5f5f5;
|
| 158 |
+
margin-bottom: 10px;
|
| 159 |
+
}
|
| 160 |
+
.preset-btn {
|
| 161 |
+
margin: 5px;
|
| 162 |
+
}
|
| 163 |
+
.compare-container {
|
| 164 |
+
display: flex;
|
| 165 |
+
gap: 10px;
|
| 166 |
+
}
|
| 167 |
+
"""
|
| 168 |
+
) as app:
|
| 169 |
+
|
| 170 |
+
# Cabeçalho
|
| 171 |
+
gr.Markdown("# ✨ Basic Adjustments")
|
| 172 |
+
gr.Markdown("### App 2 do Photoshop AI Ecosystem - Ajustes Básicos")
|
| 173 |
+
gr.Markdown("Ajuste brilho, contraste, saturação e nitidez de imagens")
|
| 174 |
+
|
| 175 |
+
with gr.Row():
|
| 176 |
+
# Coluna da esquerda - Upload e Controles
|
| 177 |
+
with gr.Column(scale=1):
|
| 178 |
+
gr.Markdown("## 📤 Importar Imagem")
|
| 179 |
+
|
| 180 |
+
# Upload com destaque
|
| 181 |
+
file_input = gr.File(
|
| 182 |
+
label="Arraste ou clique para selecionar",
|
| 183 |
+
file_types=["image"],
|
| 184 |
+
height=100
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
load_btn = gr.Button(
|
| 188 |
+
"📥 Carregar Imagem",
|
| 189 |
+
variant="primary",
|
| 190 |
+
size="lg",
|
| 191 |
+
elem_classes="load-btn"
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
status_display = gr.Textbox(
|
| 195 |
+
label="Status",
|
| 196 |
+
value="Aguardando imagem...",
|
| 197 |
+
interactive=False
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
# Presets rápidos
|
| 201 |
+
gr.Markdown("## 🎨 Presets Rápidos")
|
| 202 |
+
with gr.Row():
|
| 203 |
+
preset_vibrant = gr.Button("Vibrante", variant="secondary", size="sm")
|
| 204 |
+
preset_soft = gr.Button("Suave", variant="secondary", size="sm")
|
| 205 |
+
preset_dramatic = gr.Button("Dramático", variant="secondary", size="sm")
|
| 206 |
+
preset_retro = gr.Button("Retrô", variant="secondary", size="sm")
|
| 207 |
+
preset_bw = gr.Button("Preto & Branco", variant="secondary", size="sm")
|
| 208 |
+
|
| 209 |
+
reset_btn = gr.Button("🔄 Resetar Ajustes", variant="stop", size="lg")
|
| 210 |
+
|
| 211 |
+
# Coluna do meio - Controles de Ajuste
|
| 212 |
+
with gr.Column(scale=2):
|
| 213 |
+
gr.Markdown("## ⚙️ Controles de Ajuste")
|
| 214 |
+
|
| 215 |
+
# Brilho
|
| 216 |
+
gr.Markdown("### ☀️ Brilho")
|
| 217 |
+
brightness_slider = gr.Slider(
|
| 218 |
+
minimum=0.0,
|
| 219 |
+
maximum=2.0,
|
| 220 |
+
value=1.0,
|
| 221 |
+
step=0.05,
|
| 222 |
+
label="",
|
| 223 |
+
info="0 = Escuro total, 1 = Normal, 2 = Muito brilhante"
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
# Contraste
|
| 227 |
+
gr.Markdown("### 🎭 Contraste")
|
| 228 |
+
contrast_slider = gr.Slider(
|
| 229 |
+
minimum=0.0,
|
| 230 |
+
maximum=2.0,
|
| 231 |
+
value=1.0,
|
| 232 |
+
step=0.05,
|
| 233 |
+
label="",
|
| 234 |
+
info="0 = Sem contraste, 1 = Normal, 2 = Alto contraste"
|
| 235 |
+
)
|
| 236 |
+
auto_contrast = gr.Checkbox(label="Contraste Automático", value=False)
|
| 237 |
+
|
| 238 |
+
# Saturação
|
| 239 |
+
gr.Markdown("### 🌈 Saturação")
|
| 240 |
+
saturation_slider = gr.Slider(
|
| 241 |
+
minimum=0.0,
|
| 242 |
+
maximum=2.0,
|
| 243 |
+
value=1.0,
|
| 244 |
+
step=0.05,
|
| 245 |
+
label="",
|
| 246 |
+
info="0 = Preto & Branco, 1 = Normal, 2 = Cores intensas"
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
# Nitidez
|
| 250 |
+
gr.Markdown("### 🔍 Nitidez")
|
| 251 |
+
sharpness_slider = gr.Slider(
|
| 252 |
+
minimum=0.0,
|
| 253 |
+
maximum=2.0,
|
| 254 |
+
value=1.0,
|
| 255 |
+
step=0.05,
|
| 256 |
+
label="",
|
| 257 |
+
info="0 = Borrado, 1 = Normal, 2 = Muito nítido"
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
# Linha de Visualização
|
| 261 |
+
with gr.Row():
|
| 262 |
+
with gr.Column():
|
| 263 |
+
gr.Markdown("## 👁️ Original")
|
| 264 |
+
original_image = gr.Image(
|
| 265 |
+
label="Imagem Original",
|
| 266 |
+
type="pil",
|
| 267 |
+
interactive=False,
|
| 268 |
+
height=400
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
with gr.Column():
|
| 272 |
+
gr.Markdown("## ✨ Ajustada")
|
| 273 |
+
adjusted_image = gr.Image(
|
| 274 |
+
label="Imagem Ajustada",
|
| 275 |
+
type="pil",
|
| 276 |
+
interactive=False,
|
| 277 |
+
height=400
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
# Linha de Ações
|
| 281 |
+
with gr.Row():
|
| 282 |
+
with gr.Column():
|
| 283 |
+
gr.Markdown("## 💾 Exportar")
|
| 284 |
+
|
| 285 |
+
format_select = gr.Dropdown(
|
| 286 |
+
label="Formato de Saída",
|
| 287 |
+
choices=["PNG", "JPEG", "WEBP"],
|
| 288 |
+
value="PNG"
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
export_btn = gr.Button(
|
| 292 |
+
"📤 Exportar Imagem Ajustada",
|
| 293 |
+
variant="primary",
|
| 294 |
+
size="lg"
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
download_output = gr.File(
|
| 298 |
+
label="Download",
|
| 299 |
+
interactive=False
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
# Seção de Informações
|
| 303 |
+
with gr.Accordion("📖 Guia Rápido", open=False):
|
| 304 |
+
gr.Markdown("""
|
| 305 |
+
### Como usar:
|
| 306 |
+
|
| 307 |
+
1. **Carregue uma imagem** usando o botão acima
|
| 308 |
+
2. **Ajuste os controles** deslizantes para modificar a imagem
|
| 309 |
+
3. **Use presets** para efeitos rápidos
|
| 310 |
+
4. **Compare** original vs. ajustada
|
| 311 |
+
5. **Exporte** quando estiver satisfeito
|
| 312 |
+
|
| 313 |
+
### Dicas:
|
| 314 |
+
- **Brilho**: Ajuste a luminosidade geral
|
| 315 |
+
- **Contraste**: Aumente para mais impacto visual
|
| 316 |
+
- **Saturação**: Controle a intensidade das cores
|
| 317 |
+
- **Nitidez**: Melhore os detalhes da imagem
|
| 318 |
+
- **Contraste Automático**: Otimiza automaticamente o contraste
|
| 319 |
+
|
| 320 |
+
### Valores Recomendados:
|
| 321 |
+
- **Retratos**: Brilho 1.05, Contraste 1.1, Saturação 0.9
|
| 322 |
+
- **Paisagens**: Brilho 1.1, Contraste 1.2, Saturação 1.2
|
| 323 |
+
- **Produtos**: Brilho 1.0, Contraste 1.3, Saturação 1.0
|
| 324 |
+
""")
|
| 325 |
+
|
| 326 |
+
# Event Handlers
|
| 327 |
+
|
| 328 |
+
# Carregar imagem
|
| 329 |
+
load_btn.click(
|
| 330 |
+
fn=adjustment_app.load_image,
|
| 331 |
+
inputs=[file_input],
|
| 332 |
+
outputs=[original_image, status_display]
|
| 333 |
+
).then(
|
| 334 |
+
fn=lambda img: img if img else None,
|
| 335 |
+
inputs=[original_image],
|
| 336 |
+
outputs=[adjusted_image]
|
| 337 |
+
)
|
| 338 |
+
|
| 339 |
+
# Aplicar ajustes em tempo real
|
| 340 |
+
for slider in [brightness_slider, contrast_slider, saturation_slider, sharpness_slider, auto_contrast]:
|
| 341 |
+
slider.change(
|
| 342 |
+
fn=adjustment_app.apply_adjustments,
|
| 343 |
+
inputs=[
|
| 344 |
+
original_image,
|
| 345 |
+
brightness_slider,
|
| 346 |
+
contrast_slider,
|
| 347 |
+
saturation_slider,
|
| 348 |
+
sharpness_slider,
|
| 349 |
+
auto_contrast
|
| 350 |
+
],
|
| 351 |
+
outputs=[adjusted_image]
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
+
# Presets
|
| 355 |
+
def apply_preset(preset_name):
|
| 356 |
+
preset = adjustment_app.get_preset(preset_name)
|
| 357 |
+
return [
|
| 358 |
+
preset['brightness'],
|
| 359 |
+
preset['contrast'],
|
| 360 |
+
preset['saturation'],
|
| 361 |
+
preset['sharpness'],
|
| 362 |
+
False # auto_contrast
|
| 363 |
+
]
|
| 364 |
+
|
| 365 |
+
preset_vibrant.click(
|
| 366 |
+
fn=apply_preset,
|
| 367 |
+
inputs=[gr.Text("vibrant", visible=False)],
|
| 368 |
+
outputs=[brightness_slider, contrast_slider, saturation_slider, sharpness_slider, auto_contrast]
|
| 369 |
+
)
|
| 370 |
+
|
| 371 |
+
preset_soft.click(
|
| 372 |
+
fn=apply_preset,
|
| 373 |
+
inputs=[gr.Text("soft", visible=False)],
|
| 374 |
+
outputs=[brightness_slider, contrast_slider, saturation_slider, sharpness_slider, auto_contrast]
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
preset_dramatic.click(
|
| 378 |
+
fn=apply_preset,
|
| 379 |
+
inputs=[gr.Text("dramatic", visible=False)],
|
| 380 |
+
outputs=[brightness_slider, contrast_slider, saturation_slider, sharpness_slider, auto_contrast]
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
preset_retro.click(
|
| 384 |
+
fn=apply_preset,
|
| 385 |
+
inputs=[gr.Text("retro", visible=False)],
|
| 386 |
+
outputs=[brightness_slider, contrast_slider, saturation_slider, sharpness_slider, auto_contrast]
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
preset_bw.click(
|
| 390 |
+
fn=apply_preset,
|
| 391 |
+
inputs=[gr.Text("black_white", visible=False)],
|
| 392 |
+
outputs=[brightness_slider, contrast_slider, saturation_slider, sharpness_slider, auto_contrast]
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
# Resetar
|
| 396 |
+
def reset_all():
|
| 397 |
+
reset_vals = adjustment_app.reset_adjustments()
|
| 398 |
+
return [
|
| 399 |
+
reset_vals['brightness'],
|
| 400 |
+
reset_vals['contrast'],
|
| 401 |
+
reset_vals['saturation'],
|
| 402 |
+
reset_vals['sharpness'],
|
| 403 |
+
reset_vals['auto_contrast']
|
| 404 |
+
]
|
| 405 |
+
|
| 406 |
+
reset_btn.click(
|
| 407 |
+
fn=reset_all,
|
| 408 |
+
outputs=[brightness_slider, contrast_slider, saturation_slider, sharpness_slider, auto_contrast]
|
| 409 |
+
)
|
| 410 |
+
|
| 411 |
+
# Exportar
|
| 412 |
+
export_btn.click(
|
| 413 |
+
fn=adjustment_app.export_image,
|
| 414 |
+
inputs=[adjusted_image, format_select],
|
| 415 |
+
outputs=[download_output]
|
| 416 |
+
)
|
| 417 |
+
|
| 418 |
+
# Footer
|
| 419 |
+
gr.Markdown("---")
|
| 420 |
+
gr.Markdown("**✨ App 2 - Basic Adjustments** | Apenas ajustes básicos | Parte do Photoshop AI Ecosystem")
|
| 421 |
+
|
| 422 |
+
return app
|
| 423 |
+
|
| 424 |
+
# Ponto de entrada
|
| 425 |
+
if __name__ == "__main__":
|
| 426 |
+
interface = create_interface()
|
| 427 |
+
interface.launch(
|
| 428 |
+
server_name="0.0.0.0",
|
| 429 |
+
server_port=7861,
|
| 430 |
+
share=False,
|
| 431 |
+
debug=True
|
| 432 |
+
)
|