Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,24 +47,42 @@ init()
|
|
| 47 |
|
| 48 |
import numpy
|
| 49 |
|
|
|
|
| 50 |
def gen(seed):
|
| 51 |
numpy.random.seed(int(seed))
|
| 52 |
-
init()
|
| 53 |
-
crop()
|
| 54 |
imgArr = []
|
| 55 |
for i in range(4):
|
| 56 |
img = Image.open(str(i)+".png")
|
| 57 |
-
|
| 58 |
-
img = img.resize((64,64), Image.NEAREST)
|
| 59 |
-
|
| 60 |
imgArr.append(img)
|
| 61 |
return imgArr
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
iface = gr.Interface(
|
| 64 |
fn=gen,
|
| 65 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
| 66 |
outputs=gr.Gallery(label="Generated Skins"),
|
| 67 |
-
title = "Minecraft Skin Generator <style>img{image-rendering: pixelated;}</style>",
|
| 68 |
debug = True,
|
| 69 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
iface.launch(width=64,height=64,enable_queue=True)
|
|
|
|
| 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 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)
|