Krikoset commited on
Commit
03a7efc
1 Parent(s): 1d6a9c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -2,10 +2,15 @@ import gradio as gr
2
  import numpy as np
3
  from PIL import Image
4
 
5
- # Function to create an image with random pixels
6
  def generate_random_image(num_pixels):
7
  width, height = 100, 100 # Set the dimensions of the image (adjust as needed)
8
- image = np.random.randint(0, 256, (height, width, 3), dtype=np.uint8)
 
 
 
 
 
9
  image = Image.fromarray(image)
10
  return image
11
 
@@ -14,8 +19,8 @@ iface = gr.Interface(
14
  fn=generate_random_image,
15
  inputs="number",
16
  outputs="image",
17
- title="Random Image Generator",
18
- description="Enter the number of pixels to generate a random image.",
19
  )
20
 
21
  iface.launch()
 
2
  import numpy as np
3
  from PIL import Image
4
 
5
+ # Function to create an image with exactly num_pixels random pixels
6
  def generate_random_image(num_pixels):
7
  width, height = 100, 100 # Set the dimensions of the image (adjust as needed)
8
+ image = np.zeros((height, width, 3), dtype=np.uint8) # Create a black image
9
+ if num_pixels > 0:
10
+ random_coordinates = np.random.randint(0, width, (num_pixels, 2))
11
+ for coord in random_coordinates:
12
+ image[coord[0], coord[1]] = np.random.randint(0, 256, (3,), dtype=np.uint8) # Set random pixel color
13
+
14
  image = Image.fromarray(image)
15
  return image
16
 
 
19
  fn=generate_random_image,
20
  inputs="number",
21
  outputs="image",
22
+ title="Random Pixel Image Generator",
23
+ description="Enter the number of random pixels to generate an image.",
24
  )
25
 
26
  iface.launch()