File size: 1,152 Bytes
4b5c8eb
6bc59c8
4b5c8eb
5c0b458
0bc0f20
6bc59c8
0bc0f20
 
 
 
5c0b458
6bc59c8
 
4b5c8eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0bc0f20
 
63e901a
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
from flask import Flask, render_template, request, jsonify, send_file
from parser import parse_source_to_graph
from dataset_gen import create_dataset_entry, get_dataset_stats, upload_to_hub, OUTPUT_FILE
import os

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/parse', methods=['POST'])
def parse():
    code = request.json.get('code', '')
    return jsonify(parse_source_to_graph(code))

@app.route('/dataset/add', methods=['POST'])
def add_entry():
    code = request.json.get('code', '')
    return jsonify(create_dataset_entry(code))

@app.route('/dataset/list', methods=['GET'])
def list_entries():
    return jsonify(get_dataset_stats())

@app.route('/dataset/download', methods=['GET'])
def download_dataset():
    if os.path.exists(OUTPUT_FILE):
        return send_file(OUTPUT_FILE, as_attachment=True)
    return "No dataset found", 404

@app.route('/dataset/upload_hf', methods=['POST'])
def upload_hf():
    data = request.json
    return jsonify(upload_to_hub(data.get('token'), data.get('repo_id')))

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=7860, debug=True)