File size: 887 Bytes
1d6a9c5
 
 
 
03a7efc
1d6a9c5
 
03a7efc
 
 
 
 
 
1d6a9c5
 
 
 
 
 
 
 
03a7efc
 
1d6a9c5
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
import numpy as np
from PIL import Image

# Function to create an image with exactly num_pixels random pixels
def generate_random_image(num_pixels):
    width, height = 100, 100  # Set the dimensions of the image (adjust as needed)
    image = np.zeros((height, width, 3), dtype=np.uint8)  # Create a black image
    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)  # Set random pixel color

    image = Image.fromarray(image)
    return image

# Gradio interface
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()