DebasishDhal99
commited on
Commit
·
0e60a05
1
Parent(s):
dcddc27
Adding csv file option
Browse files
app.py
CHANGED
@@ -2,9 +2,7 @@ import matplotlib.pyplot as plt
|
|
2 |
import random
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
-
|
6 |
-
# seed = random.randint(1, 1000)
|
7 |
-
# random.seed(seed)
|
8 |
|
9 |
def generate_random_walk(iters, step_size = 1, random_seed = None):
|
10 |
# random.seed(random_seed)
|
@@ -41,6 +39,9 @@ def generate_random_walk(iters, step_size = 1, random_seed = None):
|
|
41 |
|
42 |
x = [i[0] for i in coordinate_list]
|
43 |
y = [i[1] for i in coordinate_list]
|
|
|
|
|
|
|
44 |
|
45 |
fig, ax = plt.subplots(1)
|
46 |
|
@@ -68,11 +69,13 @@ def generate_random_walk(iters, step_size = 1, random_seed = None):
|
|
68 |
|
69 |
fig.canvas.draw()
|
70 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
71 |
-
|
|
|
|
|
72 |
|
73 |
iters = gr.Number(value=1e5,label="How many random steps?")
|
74 |
step_size = gr.Number(value=1,label="Step size")
|
75 |
random_seed = gr.Number(value=42,label="Random seed (Delete it to go full random mode)")
|
76 |
|
77 |
-
iface = gr.Interface(fn=generate_random_walk, inputs=[iters, step_size, random_seed], outputs="image", title="2-D Random Walk Plot", description="Steps along NEWS directions only")
|
78 |
iface.launch()
|
|
|
2 |
import random
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
+
import pandas as pd
|
|
|
|
|
6 |
|
7 |
def generate_random_walk(iters, step_size = 1, random_seed = None):
|
8 |
# random.seed(random_seed)
|
|
|
39 |
|
40 |
x = [i[0] for i in coordinate_list]
|
41 |
y = [i[1] for i in coordinate_list]
|
42 |
+
df = pd.DataFrame({'x':x,'y':y})
|
43 |
+
csv_file = "2d_random_walk_coordinates.csv"
|
44 |
+
df.to_csv(csv_file, index=False)
|
45 |
|
46 |
fig, ax = plt.subplots(1)
|
47 |
|
|
|
69 |
|
70 |
fig.canvas.draw()
|
71 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
72 |
+
|
73 |
+
|
74 |
+
return image_array, csv_file
|
75 |
|
76 |
iters = gr.Number(value=1e5,label="How many random steps?")
|
77 |
step_size = gr.Number(value=1,label="Step size")
|
78 |
random_seed = gr.Number(value=42,label="Random seed (Delete it to go full random mode)")
|
79 |
|
80 |
+
iface = gr.Interface(fn=generate_random_walk, inputs=[iters, step_size, random_seed], outputs=["image","file"], title="2-D Random Walk Plot", description="Steps along NEWS directions only")
|
81 |
iface.launch()
|