meeww commited on
Commit
47d2a15
·
verified ·
1 Parent(s): 8ecee54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -47,41 +47,40 @@ init()
47
 
48
  import numpy
49
 
50
- # Function to generate images based on a seed
51
- def gen(seed):
52
- numpy.random.seed(int(seed))
 
 
 
53
  init() # Initialize and generate samples
54
  crop() # Crop the generated images
55
  imgArr = []
56
  for i in range(4):
57
- img = Image.open(str(i)+".png")
58
  img = img.resize((64, 64), Image.NEAREST)
59
  imgArr.append(img)
60
  return imgArr
61
 
62
-
63
- # Function to handle input, deciding based on user choice
64
- def handle_input(seed, action):
65
- if action == "Surprise Me":
66
- seed = random.randint(0, 1000)
67
- return gen(seed)
 
68
 
69
 
70
 
71
  iface = gr.Interface(
72
  fn=handle_input,
73
  inputs=[
74
- gr.Text(label="Seed", placeholder="Enter a seed or use 'Surprise Me'"), # Text input for seed
75
- gr.Radio(choices=["Generate", "Surprise Me"], label="Action", default="Generate"), # Radio buttons to select action
76
  ],
77
  outputs=gr.Gallery(label="Generated Skins"),
78
  title = "Minecraft Skin Generator <style>img{image-rendering: pixelated;}</style>", #<-- EWW GROSS IK IK IM SORRY, BUT THAT'S THE ONLY WAY I FOUND IT TO WORK
79
  debug = True,
80
  )
81
- # Adding a 'Surprise Me' button that does not require input and calls the same function without a seed
82
- iface.add_component(gr.Button("Surprise Me"),
83
- fn=lambda: handle_input(),
84
- inputs=[],
85
- outputs=iface.outputs)
86
 
87
  iface.launch()
 
47
 
48
  import numpy
49
 
50
+ def gen(seed=None):
51
+ if seed is None or seed == "Surprise Me":
52
+ seed = random.randint(0, 1000)
53
+ else:
54
+ seed = int(seed)
55
+ np.random.seed(seed)
56
  init() # Initialize and generate samples
57
  crop() # Crop the generated images
58
  imgArr = []
59
  for i in range(4):
60
+ img = Image.open(f"{i}.png").convert('RGB')
61
  img = img.resize((64, 64), Image.NEAREST)
62
  imgArr.append(img)
63
  return imgArr
64
 
65
+
66
+ # Function to handle the input from the interface
67
+ def handle_input(seed_text, surprise_me):
68
+ if surprise_me:
69
+ return gen("Surprise Me")
70
+ else:
71
+ return gen(seed_text)
72
 
73
 
74
 
75
  iface = gr.Interface(
76
  fn=handle_input,
77
  inputs=[
78
+ gr.Text(label="Seed", placeholder="Enter a seed"), # Text input for seed
79
+ gr.Checkbox(label="Surprise Me", value=False), # Checkbox for 'Surprise Me' functionality
80
  ],
81
  outputs=gr.Gallery(label="Generated Skins"),
82
  title = "Minecraft Skin Generator <style>img{image-rendering: pixelated;}</style>", #<-- EWW GROSS IK IK IM SORRY, BUT THAT'S THE ONLY WAY I FOUND IT TO WORK
83
  debug = True,
84
  )
 
 
 
 
 
85
 
86
  iface.launch()