import gradio as gr import cv2 import numpy as np from PIL import Image import torch from torchvision import transforms import warnings warnings.filterwarnings('ignore') # Función simple de upscaling usando OpenCV def simple_upscale(image, scale_factor=4, method='cubic'): """ Upscaling simple usando interpolación """ if image is None: return None img = np.array(image) # Métodos de interpolación methods = { 'nearest': cv2.INTER_NEAREST, 'linear': cv2.INTER_LINEAR, 'cubic': cv2.INTER_CUBIC, 'lanczos': cv2.INTER_LANCZOS4 } # Calcular nuevo tamaño height, width = img.shape[:2] new_width = int(width * scale_factor) new_height = int(height * scale_factor) # Upscale if len(img.shape) == 3: # Color upscaled = cv2.resize( img, (new_width, new_height), interpolation=methods.get(method, cv2.INTER_CUBIC) ) else: # Grayscale upscaled = cv2.resize( img, (new_width, new_height), interpolation=methods.get(method, cv2.INTER_CUBIC) ) # Aplicar sharpening kernel = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]]) sharpened = cv2.filter2D(upscaled, -1, kernel) return Image.fromarray(sharpened) # Interfaz simple def create_simple_interface(): with gr.Blocks(title="Mejorador Simple de Imágenes") as app: gr.Markdown("# 🖼️ Mejorador de Imágenes Simple") with gr.Row(): with gr.Column(): input_img = gr.Image(type="pil", label="Imagen Original") scale = gr.Slider(1, 8, 4, step=1, label="Factor de Escala") method = gr.Dropdown( ['nearest', 'linear', 'cubic', 'lanczos'], value='cubic', label="Método de Interpolación" ) btn = gr.Button("Mejorar", variant="primary") with gr.Column(): output_img = gr.Image(type="pil", label="Imagen Mejorada") btn.click( fn=simple_upscale, inputs=[input_img, scale, method], outputs=output_img ) return app if __name__ == "__main__": app = create_simple_interface() app.launch()