File size: 3,031 Bytes
b8b84f7 e3d105a b8b84f7 ec90544 b8b84f7 3f8b6fd b8b84f7 22285df b8b84f7 22285df 1a2363c b8b84f7 22285df 1a2363c 22285df 1a2363c 22285df b8b84f7 ec90544 22285df ec90544 b8b84f7 22285df ec90544 22285df ec90544 22285df ec90544 b8b84f7 ec90544 b8b84f7 22285df 315f099 ec90544 22285df ec90544 b8b84f7 22285df b8b84f7 ec90544 1a2363c b8b84f7 | 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | from flask import Flask, render_template, request, jsonify
from processor import DatasetCommandCenter
import requests
import threading
import uuid
import json
app = Flask(__name__)
jobs = {}
@app.route('/')
def index():
return render_template('index.html')
@app.route('/analyze_metadata', methods=['POST'])
def analyze_metadata():
data = request.json
center = DatasetCommandCenter(token=data.get('token'))
return jsonify(center.get_dataset_metadata(data.get('dataset_id')))
@app.route('/get_splits', methods=['POST'])
def get_splits():
data = request.json
center = DatasetCommandCenter(token=data.get('token'))
return jsonify(center.get_splits_for_config(data.get('dataset_id'), data.get('config')))
@app.route('/inspect_rows', methods=['POST'])
def inspect_rows():
data = request.json
center = DatasetCommandCenter(token=data.get('token'))
return jsonify(center.inspect_dataset(
data.get('dataset_id'), data.get('config'), data.get('split')
))
@app.route('/preview', methods=['POST'])
def preview():
data = request.json
recipe = data.get('recipe', {})
# DEBUG LOGGING
print("="*60)
print("PREVIEW REQUEST RECEIVED")
print("="*60)
print("Dataset:", data.get('dataset_id'))
print("Config:", data.get('config'))
print("Split:", data.get('split'))
print("Recipe:")
print(json.dumps(recipe, indent=2))
print("="*60)
center = DatasetCommandCenter(token=data.get('token'))
try:
rows = center.preview_transform(
data.get('dataset_id'),
data.get('config'),
data.get('split'),
recipe
)
print(f"Preview successful: {len(rows)} rows returned")
return jsonify({"status": "success", "rows": rows})
except Exception as e:
print(f"PREVIEW ERROR: {str(e)}")
import traceback
traceback.print_exc()
return jsonify({"status": "error", "message": str(e)})
@app.route('/execute', methods=['POST'])
def execute():
data = request.json
job_id = str(uuid.uuid4())
token = data.get('token')
center = DatasetCommandCenter(token=token)
args = (
data.get('dataset_id'),
data.get('config'),
data.get('split'),
data.get('target_id'),
data.get('recipe', {}),
data.get('max_rows'),
data.get('license')
)
def task():
try:
jobs[job_id] = {"status": "running"}
res = center.process_and_push(*args)
jobs[job_id] = {"status": "completed", "result": res}
except Exception as e:
jobs[job_id] = {"status": "failed", "error": str(e)}
threading.Thread(target=task).start()
return jsonify({"status": "started", "job_id": job_id})
@app.route('/status/<job_id>', methods=['GET'])
def status(job_id):
return jsonify(jobs.get(job_id, {"status": "unknown"}))
if __name__ == '__main__':
app.run(debug=True, port=7860, host="0.0.0.0") |