Spaces:
Sleeping
Sleeping
File size: 1,928 Bytes
c291038 09f08b3 c291038 09f08b3 c291038 |
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 53 54 55 56 |
# app.py
from flask import Flask, send_from_directory, jsonify, request
import os
app = Flask(__name__)
# Updated simulation parameters with real-world masses (scaled down for simulation)
# Sun: 1.989 x 10^30 kg, Earth: 5.972 x 10^24 kg, Mars: 6.417 x 10^23 kg
# Scale factor: 1e-26 for manageable numbers
simulation_params = {
"sun": {
"mass": 1.989e4, # Scaled mass (1.989 x 10^30 kg * 1e-26)
"position": [0, 0, 0],
"orbital_velocity": 0, # Sun is stationary
},
"earth": {
"mass": 5.972e-2, # Scaled mass (5.972 x 10^24 kg * 1e-26)
"position": [10, 0, 0], # Approx 1 AU scaled down (149.6 million km -> 10 units)
"orbital_velocity": 0.0298, # 29.8 km/s scaled down
},
"mars": {
"mass": 6.417e-3, # Scaled mass (6.417 x 10^23 kg * 1e-26)
"position": [15, 0, 0], # Approx 1.52 AU scaled down (227.9 million km -> 15 units)
"orbital_velocity": 0.0241, # 24.1 km/s scaled down
},
"fluid_speed": 0.1,
"fluid_friction": 0.9, # Default friction factor
"fluid_deflection": 0.1, # Default deflection strength
}
# Serve the frontend
@app.route('/')
def serve_index():
return send_from_directory('static', 'index.html')
# Serve static files (CSS, JS)
@app.route('/static/<path:path>')
def serve_static(path):
return send_from_directory('static', path)
# API to get simulation parameters
@app.route('/api/params', methods=['GET'])
def get_params():
return jsonify(simulation_params)
# API to update simulation parameters
@app.route('/api/params', methods=['POST'])
def update_params():
global simulation_params
data = request.get_json()
simulation_params.update(data)
return jsonify({"status": "success", "params": simulation_params})
if __name__ == '__main__':
port = int(os.environ.get('PORT', 7860)) # Default port for Hugging Face Spaces
app.run(host='0.0.0.0', port=port) |