mathildekappel commited on
Commit
7274c87
·
1 Parent(s): fdde807

test traj

Browse files
Files changed (1) hide show
  1. app.py +69 -3
app.py CHANGED
@@ -1,7 +1,73 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ from mpl_toolkits.mplot3d import Axes3D
5
 
 
 
6
 
7
+ # -----------------------------
8
+ # Generate 3 synthetic trajectories
9
+ # -----------------------------
10
+ def generate_trajectories(n=200):
11
+ t = np.linspace(0, 10, n)
12
+
13
+ traj1 = np.vstack([
14
+ np.sin(t),
15
+ np.cos(t),
16
+ t * 0.2
17
+ ]).T
18
+
19
+ traj2 = np.vstack([
20
+ np.sin(t) * np.cos(t),
21
+ np.sin(t),
22
+ np.cos(t * 0.5)
23
+ ]).T
24
+
25
+ traj3 = np.vstack([
26
+ t * 0.1,
27
+ np.sin(t * 2),
28
+ np.cos(t * 2) + np.sin(t * 0.5)
29
+ ]).T
30
+
31
+ return {
32
+ "Trajectory 1 (helix-like)": traj1,
33
+ "Trajectory 2 (oscillating)": traj2,
34
+ "Trajectory 3 (mixed wave)": traj3
35
+ }
36
+
37
+
38
+ TRAJECTORIES = generate_trajectories()
39
+
40
+
41
+ # -----------------------------
42
+ # Plot function
43
+ # -----------------------------
44
+ def plot_trajectory(choice):
45
+ traj = TRAJECTORIES[choice]
46
+
47
+ fig = plt.figure()
48
+ ax = fig.add_subplot(111, projection='3d')
49
+
50
+ ax.plot(traj[:, 0], traj[:, 1], traj[:, 2])
51
+
52
+ ax.set_title(choice)
53
+ ax.set_xlabel("X")
54
+ ax.set_ylabel("Y")
55
+ ax.set_zlabel("Z")
56
+
57
+ return fig
58
+
59
+
60
+ # -----------------------------
61
+ # Gradio UI
62
+ # -----------------------------
63
+ choices = list(TRAJECTORIES.keys())
64
+
65
+ demo = gr.Interface(
66
+ fn=plot_trajectory,
67
+ inputs=gr.Dropdown(choices, label="Choose trajectory"),
68
+ outputs=gr.Plot(label="3D Trajectory"),
69
+ title="3D Trajectory Viewer",
70
+ description="Select one of 3 generated trajectories and visualize it in 3D."
71
+ )
72
+
73
  demo.launch()