pixelC / app.py
Krikoset's picture
Update app.py
03a7efc
raw
history blame contribute delete
No virus
887 Bytes
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()