gravity-dev / app.py
broadfield-dev's picture
Update app.py
09f08b3 verified
raw
history blame
1.93 kB
# 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)