gravity / app.py
broadfield-dev's picture
Create app.py
c291038 verified
# app.py
from flask import Flask, send_from_directory, jsonify, request
import os
app = Flask(__name__)
# Default simulation parameters
simulation_params = {
"brown_sphere": {"mass": 92, "position": [0, 0, 0]},
"green_sphere": {"mass": 29, "position": [5, 0, 5]},
"red_sphere": {"mass": 10, "position": [-5, 0, -5]},
"fluid_speed": 0.1
}
# 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)