meeww commited on
Commit
fba866e
·
verified ·
1 Parent(s): eae2e25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -15
app.py CHANGED
@@ -60,29 +60,26 @@ def gen(seed):
60
  return imgArr
61
 
62
 
63
- # Function to generate a random seed and then generate images
64
- def surprise_me():
65
- import random
66
- seed = random.randint(0, 1000)
67
  return gen(seed)
68
 
69
 
70
  iface = gr.Interface(
71
- fn=gen,
72
  inputs=[
73
- gr.Text(label="Seed", default="500"), # Allow manual seed input
74
- gr.Button("Surprise Me") # Add a "Surprise Me" button
75
  ],
76
  outputs=gr.Gallery(label="Generated Skins"),
77
  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
78
  debug = True,
79
  )
80
- # Define what happens when the "Surprise Me" button is clicked
81
- iface.add_component(
82
- component=gr.Button("Surprise Me"),
83
- fn=surprise_me,
84
- inputs=[],
85
- outputs=[gr.Gallery(label="Generated Skins")]
86
- )
87
 
88
- iface.launch(width=64,height=64,enable_queue=True)
 
60
  return imgArr
61
 
62
 
63
+ # New function to handle text input or surprise me functionality
64
+ def handle_input(seed=None):
65
+ if seed is None or seed == "":
66
+ seed = random.randint(0, 1000)
67
  return gen(seed)
68
 
69
 
70
  iface = gr.Interface(
71
+ fn=handle_input,
72
  inputs=[
73
+ gr.Text(label="Seed"), # Text input for seed
 
74
  ],
75
  outputs=gr.Gallery(label="Generated Skins"),
76
  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
77
  debug = True,
78
  )
79
+ # Adding a 'Surprise Me' button that does not require input and calls the same function without a seed
80
+ iface.add_component(gr.Button("Surprise Me"),
81
+ fn=lambda: handle_input(),
82
+ inputs=[],
83
+ outputs=iface.outputs)
 
 
84
 
85
+ iface.launch()