Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -47,41 +47,40 @@ init()
|
|
47 |
|
48 |
import numpy
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
53 |
init() # Initialize and generate samples
|
54 |
crop() # Crop the generated images
|
55 |
imgArr = []
|
56 |
for i in range(4):
|
57 |
-
img = Image.open(
|
58 |
img = img.resize((64, 64), Image.NEAREST)
|
59 |
imgArr.append(img)
|
60 |
return imgArr
|
61 |
|
62 |
-
|
63 |
-
# Function to handle input
|
64 |
-
def handle_input(
|
65 |
-
if
|
66 |
-
|
67 |
-
|
|
|
68 |
|
69 |
|
70 |
|
71 |
iface = gr.Interface(
|
72 |
fn=handle_input,
|
73 |
inputs=[
|
74 |
-
gr.Text(label="Seed", placeholder="Enter a seed
|
75 |
-
gr.
|
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()
|