Spaces:
Runtime error
Runtime error
from asyncio import constants | |
import gradio as gr | |
import requests | |
import os | |
import re | |
import random | |
import numpy as np | |
from perlin_numpy import generate_fractal_noise_2d | |
def create_fractal_noise(input_seed,input_size,res,n_octaves,persistence): | |
""" | |
Generate fractal noise using the Perlin noise algorithm. | |
""" | |
np.random.seed(input_seed) | |
n = generate_fractal_noise_2d((input_size, input_size), (res, res), n_octaves, persistence) | |
#reshape | |
n3=np.repeat(n[:,:,np.newaxis],3,axis=2) | |
#change from [-1,1] to [0,255] | |
n3=(n3+1)/2*255 | |
#change type to int64 | |
n3=n3.astype(np.int64) | |
return n3 | |
demo = gr.Blocks() | |
with demo: | |
gr.Markdown("<h1><center>fractalNoise</center></h1>") | |
gr.Markdown( | |
"<div>Create fractal-like noise (useful for map generation and such)</div>" | |
"<div>Using pvigier's <a href=https://github.com/pvigier/perlin-numpy>perlin-numpy</a></div>" | |
) | |
with gr.Row(): | |
input_seed = gr.Number(label="seed",value=0,precision=0) | |
input_size = seed=gr.Number(value=256, label='size',precision=0) | |
res=gr.Number(value=2, label='res',precision=0) | |
n_octaves=gr.Number(value=8, label='n-octaves',precision=0) | |
persistence=gr.Number(value=0.5, label='persistence') | |
with gr.Row(): | |
b0 = gr.Button("Submit") | |
with gr.Row(): | |
output_image = gr.outputs.Image(type="filepath", label='Output') | |
b0.click(create_fractal_noise,inputs=[input_seed,input_size,res,n_octaves,persistence],outputs=[output_image]) | |
#examples=examples | |
demo.launch(enable_queue=True, debug=True) |