Spaces:
Runtime error
Runtime error
File size: 1,624 Bytes
c7ce504 72d2c17 c7ce504 72d2c17 76af870 c7ce504 fcd5d54 c7ce504 fcd5d54 c7ce504 fcd5d54 c7ce504 8e31e74 c7ce504 36cce5e 76af870 36cce5e c71253d c7ce504 8e31e74 e4e8a26 c7ce504 e4e8a26 c7ce504 8e31e74 c7ce504 |
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 44 45 46 47 48 49 50 51 52 |
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) |