Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import cv2 | |
| import numpy as np | |
| import torch | |
| from PIL import Image | |
| # Dummy functions (replace with actual Material-Map-Generator logic if you have the models) | |
| def generate_normal_map(image): | |
| # Placeholder: Convert to grayscale and apply Sobel filter | |
| img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY) | |
| sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=5) | |
| sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=5) | |
| normal = np.dstack((sobelx, sobely, np.ones_like(img) * 255)) | |
| return Image.fromarray(np.uint8(normal)) | |
| def generate_displacement_map(image): | |
| # Placeholder: Convert to grayscale | |
| img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY) | |
| return Image.fromarray(img) | |
| def generate_roughness_map(image): | |
| # Placeholder: Invert grayscale | |
| img = 255 - cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY) | |
| return Image.fromarray(img) | |
| def process_image(input_image): | |
| normal_map = generate_normal_map(input_image) | |
| displacement_map = generate_displacement_map(input_image) | |
| roughness_map = generate_roughness_map(input_image) | |
| return normal_map, displacement_map, roughness_map | |
| # Gradio Interface | |
| interface = gr.Interface( | |
| fn=process_image, | |
| inputs=gr.Image(type="pil", label="Upload Image"), | |
| outputs=[ | |
| gr.Image(type="pil", label="Normal Map"), | |
| gr.Image(type="pil", label="Displacement Map"), | |
| gr.Image(type="pil", label="Roughness Map") | |
| ], | |
| title="Material Map Generator", | |
| description="Upload an image to generate Normal, Displacement, and Roughness maps." | |
| ) | |
| interface.launch() |