File size: 973 Bytes
159276a
 
 
 
 
 
 
 
9b0275c
 
159276a
 
 
 
b39a992
159276a
9b0275c
 
 
 
 
 
 
 
 
159276a
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import json
import datetime
import huggingface_hub as hh
from flask import Flask, request
repo_id = 'microbamboo/tennisjson'
app = Flask(__name__)

@app.route("/backUP", methods = ['POST'])
def backUP():
    d = request.json
    now = str(datetime.datetime.now()).replace(':', '_')
    json.dump(d, open(now, 'w'))
    hh.upload_file(path_or_fileobj=now, path_in_repo=now, repo_id=repo_id, repo_type='dataset', token=True)
    return now

@app.route("/backDOWN", methods = ['POST'])
def backDOWN():
    d = request.json
    file = d['file']
    f = hh.hf_hub_download(repo_id, filename=file, repo_type='dataset')
    s = open(f).read()
    return s


@app.route("/put", methods = ['POST'])
def put():
    d = request.headers
    file = d['File']
    folder = os.path.split(file)[0]
    os.makedirs(folder, exist_ok=True)
    f = request.files['file']
    f.save(file)
    return "ok"


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