hamaadayubkhan commited on
Commit
567b57c
·
verified ·
1 Parent(s): 6b340d9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary packages
2
+ import simpy
3
+ import matplotlib.pyplot as plt
4
+ from mpl_toolkits.mplot3d import Axes3D # for 3D plotting
5
+ from PIL import Image
6
+ import gradio as gr
7
+ import io
8
+
9
+ # Function for jet flight simulation using SimPy with 3D plot
10
+ def run_jet_simulation(max_altitude, climb_rate, acceleration, max_speed_kmph):
11
+ max_speed_mps = max_speed_kmph * 1000 / 3600
12
+
13
+ time_log = []
14
+ altitude_log = []
15
+ speed_log = []
16
+
17
+ def jet_process(env):
18
+ altitude = 0
19
+ speed = 0
20
+ while True:
21
+ if altitude < max_altitude:
22
+ altitude += climb_rate
23
+ if speed < max_speed_mps:
24
+ speed += acceleration
25
+ time_log.append(env.now)
26
+ altitude_log.append(min(altitude, max_altitude))
27
+ speed_log.append(min(speed, max_speed_mps))
28
+ yield env.timeout(1)
29
+ if altitude >= max_altitude and speed >= max_speed_mps:
30
+ break
31
+
32
+ env = simpy.Environment()
33
+ env.process(jet_process(env))
34
+ env.run(until=300)
35
+
36
+ # 3D Plotting
37
+ fig = plt.figure(figsize=(8, 6))
38
+ ax = fig.add_subplot(111, projection='3d')
39
+ ax.plot(time_log, altitude_log, speed_log, color='blue', label='Jet Climb Path')
40
+ ax.set_xlabel('Time (s)')
41
+ ax.set_ylabel('Altitude (m)')
42
+ ax.set_zlabel('Speed (m/s)')
43
+ ax.set_title('🛩️ 3D Jet Climb Simulation')
44
+ ax.legend()
45
+
46
+ # Save to buffer
47
+ buf = io.BytesIO()
48
+ plt.savefig(buf, format='png')
49
+ buf.seek(0)
50
+ return Image.open(buf)
51
+
52
+ # Gradio Interface
53
+ demo = gr.Interface(
54
+ fn=run_jet_simulation,
55
+ inputs=[
56
+ gr.Number(label="Max Altitude (meters)", value=10000),
57
+ gr.Number(label="Climb Rate (m/s)", value=50),
58
+ gr.Number(label="Acceleration (m/s²)", value=20),
59
+ gr.Number(label="Max Speed (km/h)", value=2500),
60
+ ],
61
+ outputs=gr.Image(type="pil"),
62
+ title="🛩️ 3D Fighter Jet Simulation using SimPy",
63
+ description="Simulates a fighter jet’s altitude and speed climb in 3D space using SimPy and Matplotlib."
64
+ )
65
+
66
+ demo.launch()