Spaces:
Sleeping
Sleeping
| import os | |
| import subprocess | |
| from flask import Flask, request, jsonify, send_from_directory | |
| app = Flask(__name__) | |
| DATA_DIR = "/data" | |
| os.makedirs(DATA_DIR, exist_ok=True) | |
| import subprocess | |
| import os | |
| def debug_conllu(): | |
| base = "/usr/src/ConlluEditor" | |
| if not os.path.exists(base): | |
| return f"Directory does not exist: {base}" | |
| try: | |
| ls_output = subprocess.check_output( | |
| ["bash", "-c", f"ls -R {base}"], | |
| stderr=subprocess.STDOUT | |
| ).decode() | |
| except subprocess.CalledProcessError as e: | |
| ls_output = f"ls failed:\n{e.output.decode()}" | |
| try: | |
| grep_output = subprocess.check_output( | |
| ["bash", "-c", f"grep -R \"12345\" {base} || true"], | |
| stderr=subprocess.STDOUT | |
| ).decode() | |
| except subprocess.CalledProcessError as e: | |
| grep_output = f"grep failed:\n{e.output.decode()}" | |
| return f"=== ls -R ===\n{ls_output}\n\n=== grep ===\n{grep_output}" | |
| def debug(): | |
| return debug_conllu(), 200, {"Content-Type": "text/plain"} | |
| def upload(): | |
| if "file" not in request.files: | |
| return "No file", 400 | |
| f = request.files["file"] | |
| if f.filename == "": | |
| return "Empty filename", 400 | |
| if not f.filename.endswith(".conllu"): | |
| return "Only .conllu allowed", 400 | |
| save_path = os.path.join(DATA_DIR, f.filename) | |
| f.save(save_path) | |
| return "OK", 200 | |
| def list_files(): | |
| files = [f for f in os.listdir(DATA_DIR) if f.endswith(".conllu")] | |
| return jsonify(files) | |
| def download(filename): | |
| return send_from_directory(DATA_DIR, filename, as_attachment=True) | |
| if __name__ == "__main__": | |
| import argparse | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--port", type=int, default=5556) | |
| args = parser.parse_args() | |
| app.run(host="0.0.0.0", port=args.port) | |