|
import gradio as gr |
|
import numpy as np |
|
from PIL import Image |
|
|
|
|
|
def generate_random_image(num_pixels): |
|
width, height = 100, 100 |
|
image = np.zeros((height, width, 3), dtype=np.uint8) |
|
if num_pixels > 0: |
|
random_coordinates = np.random.randint(0, width, (num_pixels, 2)) |
|
for coord in random_coordinates: |
|
image[coord[0], coord[1]] = np.random.randint(0, 256, (3,), dtype=np.uint8) |
|
|
|
image = Image.fromarray(image) |
|
return image |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_random_image, |
|
inputs="number", |
|
outputs="image", |
|
title="Random Pixel Image Generator", |
|
description="Enter the number of random pixels to generate an image.", |
|
) |
|
|
|
iface.launch() |
|
|