Spaces:
Runtime error
Runtime error
File size: 1,206 Bytes
f1b77e3 99fcaac 50f526d f1b77e3 50f526d f1b77e3 50f526d f1b77e3 99fcaac f1b77e3 50f526d f1b77e3 50f526d f1b77e3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import gradio as gr
import subprocess
import os
# Define the function to generate images
def generate_images(seeds, trunc):
# Define the path to the model
NETWORK_PATH = 'network-snapshot-000064.pkl'
# Define the output directory
OUTPUT_DIR = 'images/'
# Ensure the output directory exists
os.makedirs(OUTPUT_DIR, exist_ok=True)
# Run the Python script for generating images
command = [
'python', 'stylegan2-ada-pytorch/generate.py',
'--outdir', OUTPUT_DIR,
'--trunc', str(trunc),
'--seeds', seeds,
'--network', NETWORK_PATH
]
subprocess.run(command, check=True)
# Find the generated image file
generated_image = os.path.join(OUTPUT_DIR, f'seed{seeds}.png')
return generated_image
# Define the Gradio interface
iface = gr.Interface(
fn=generate_images,
inputs=[
gr.Textbox(label="Seeds", value="0"),
gr.Slider(label="Truncation", minimum=0, maximum=1, step=0.1, value=0.8)
],
outputs=gr.Image(type="filepath", label="Generated Image"),
title="Image Generator",
description="Generate images using StyleGAN2-ADA."
)
if __name__ == "__main__":
iface.launch()
|