Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions web_app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Antigravity Coder

This is a native web application that provides an online coding environment with instance management and traffic phasing capabilities.

## Features

1. **Online Coder**: Write and execute Python code directly in the browser.
2. **Instance Management**: Deploy new versions of your code as separate instances.
3. **Phase in Shift**: Gradually shift traffic from the stable version to the new candidate version using a percentage slider.
4. **Rollback**: Quickly revert to any previous version.
5. **Antigravity Mode**: A "Google Antigravity" inspired visual mode.

## How to Run

1. Install dependencies:
```bash
pip install -r requirements.txt
```

2. Run the application:
```bash
python app.py
```

3. Open `http://localhost:5000` in your browser.

## usage

- **Code Editor**: Type your Python code in the text area.
- **Deploy**: Click "Deploy as New Instance" to save the current code as a new version (e.g., v2, v3).
- **Phase Shift**: Use the slider to control the probability (0-100%) that the "Execute" button runs the *New Candidate* instead of the *Current Stable*.
- **Execute**: Runs the code. The output shows which version was executed based on the phase shift setting.
- **Rollback**: Click "Rollback To" in the history list to make a previous version the "Current Stable" and reset phase shift to 0.
78 changes: 78 additions & 0 deletions web_app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from flask import Flask, render_template, request, jsonify
import sys

Check failure on line 2 in web_app/app.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

web_app/app.py:2:8: F401 `sys` imported but unused
import io
import contextlib
import random

app = Flask(__name__)

# State
instances = {
"v1": "print('Hello World from v1')",
}
current_version = "v1"
next_version = None
phase_shift = 0.0 # 0.0 to 1.0 (0% to 100% traffic to next_version)

@app.route('/')
def index():
return render_template('index.html',
instances=instances,
current_version=current_version,
next_version=next_version,
phase_shift=phase_shift)

@app.route('/deploy', methods=['POST'])
def deploy():
global next_version, instances
code = request.json.get('code')
version_name = f"v{len(instances) + 1}"
instances[version_name] = code
next_version = version_name
return jsonify({"status": "success", "version": version_name})

@app.route('/rollback', methods=['POST'])
def rollback():
global current_version, next_version, phase_shift
target_version = request.json.get('version')
if target_version in instances:
current_version = target_version
next_version = None
phase_shift = 0.0
return jsonify({"status": "success"})
return jsonify({"status": "error", "message": "Version not found"}), 404

@app.route('/phase', methods=['POST'])
def set_phase():
global phase_shift
shift = float(request.json.get('shift', 0))
if 0 <= shift <= 100:
phase_shift = shift / 100.0
return jsonify({"status": "success", "phase": phase_shift})
return jsonify({"status": "error"}), 400

@app.route('/execute', methods=['POST'])
def execute():
# Simulate traffic shifting
version_to_run = current_version
if next_version and random.random() < phase_shift:
version_to_run = next_version

code = instances.get(version_to_run, "")

# Capture stdout
f = io.StringIO()
try:
with contextlib.redirect_stdout(f):
exec(code)
result = f.getvalue()
except Exception as e:
result = str(e)

return jsonify({
"result": result,
"version_executed": version_to_run
})

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
1 change: 1 addition & 0 deletions web_app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
Loading