Spaces:
Runtime error
Runtime error
Logan Zoellner
commited on
Commit
·
c7ce504
1
Parent(s):
7e5faeb
initial commit
Browse files- app.py +48 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from asyncio import constants
|
2 |
+
import gradio as gr
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
+
import re
|
6 |
+
import random
|
7 |
+
import numpy as np
|
8 |
+
from perlin_numpy import generate_fractal_noise_2d
|
9 |
+
|
10 |
+
def create_fractal_noise(size,n_octaves, n_layers, seed):
|
11 |
+
"""
|
12 |
+
Generate fractal noise using the Perlin noise algorithm.
|
13 |
+
"""
|
14 |
+
np.random.seed(0)
|
15 |
+
noise = generate_fractal_noise_2d((256, 256), (8, 8), 5)
|
16 |
+
#reshape
|
17 |
+
n3=np.repeat(n[:,:,np.newaxis],3,axis=2)
|
18 |
+
#change from [-1,1] to [0,255]
|
19 |
+
n3=(n3+1)/2*255
|
20 |
+
return n3
|
21 |
+
|
22 |
+
demo = gr.Blocks()
|
23 |
+
|
24 |
+
with demo:
|
25 |
+
gr.Markdown("<h1><center>LiteDungeon</center></h1>")
|
26 |
+
gr.Markdown(
|
27 |
+
"<div>Create fractal-like noise (useful for map generation and such)</div>"
|
28 |
+
)
|
29 |
+
|
30 |
+
with gr.Row():
|
31 |
+
output_story = gr.Textbox(value=default_story,label="story",lines=7)
|
32 |
+
|
33 |
+
with gr.Row():
|
34 |
+
input_seed = gr.Number(label="seed",value=0)
|
35 |
+
input_size = seed=gr.Number(default=256, label='size')
|
36 |
+
res=gr.Number(default=2, label='res')
|
37 |
+
n_octaves=gr.Number(default=2, label='n-octaves')
|
38 |
+
persistence=gr.Number(default=0.5, label='persistence')
|
39 |
+
|
40 |
+
output_image = gr.outputs.Image(type="filepath", label='Output')
|
41 |
+
|
42 |
+
with gr.Row():
|
43 |
+
b0 = gr.Button("Submit")
|
44 |
+
|
45 |
+
b0.click(create_fractal_noise,inputs=[input_seed,input_size,res,n_octaves,persistencen],outputs=[output_image])
|
46 |
+
#examples=examples
|
47 |
+
|
48 |
+
demo.launch(enable_queue=True, debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
numpy==1.22.3
|
2 |
+
git+https://github.com/pvigier/perlin-numpy
|