Spaces:
Sleeping
Sleeping
| # -*- coding: utf-8 -*- | |
| ##!kill -9 "$(pgrep ngrok)" | |
| import sys; import os; cpa=os.environ.get("cpa") | |
| import subprocess,re,requests,threading | |
| def repo_clone(url, dir, branch=None): | |
| subprocess.run([b'\x67\x69\x74'.decode(), b'\x63\x6C\x6F\x6E\x65'.decode(), url, dir], check=True) | |
| if branch: | |
| subprocess.run(["git", "checkout", branch], cwd=dir, check=True) | |
| ##if os.path.isdir(f:="ciph"): repo_clone("https://huggingface.co/spaces/compileprincess/ciph") | |
| # | |
| face="1000" | |
| ##face="face" | |
| if os.environ.get("SPACE_HOST"): face="face" | |
| if face=="face":#1 | |
| sys.path.append("/home/user/app") | |
| elif not cpa: | |
| from google.colab import drive | |
| drive.mount('/content/gdrive/', force_remount=True) | |
| sys.path.append("/content/gdrive/MyDrive/w") | |
| os.environ["tmp"]="/tmp"; os.makedirs("/tmp",exist_ok=True) | |
| else: | |
| import sys;import os;sys.path.append(os.environ["AlfiPython"]+r"\Mjmoji"); | |
| ##from wr import wfd, inidi, impt, time | |
| from wr import * | |
| import flask as flas | |
| from flask import Flask, render_template, request, redirect, Response | |
| def disablelog(): | |
| import flask.cli | |
| flask.cli.show_server_banner = lambda *w: None | |
| import logging | |
| logging.getLogger(b'\x77\x65\x72\x6B\x7A\x65\x75\x67'.decode()).disabled = True# log of flas | |
| disablelog() | |
| import json | |
| app = Flask(__name__) | |
| app.mimi=hhwr() | |
| app.t0=time.perf_counter() | |
| handle_post="/handle_post" | |
| if face=="face": | |
| mid="/home/user/app" | |
| mid="" | |
| #handle_post=os.environ.get("handle_post") | |
| elif not cpa: | |
| mid=("/content/gdrive/MyDrive/w") | |
| from pyngrok import conf, ngrok | |
| ## exec("conf.get_default().auth_"+b'\x74\x6F\x6B\x65\x6E'.decode()+" = sign" | |
| port=5000 | |
| conf.get_default().monitor_thread = False | |
| try: | |
| public_url = ngrok.connect(port).public_url | |
| except: | |
| ngrok.kill() | |
| sys.exit() | |
| print("tunnel \"{}\" -> \"http://127.0.0.1:{}\"".format(public_url, port)) | |
| app.config["BASE_URL"] = public_url | |
| # | |
| def pr2(*w): print(*w) | |
| def run1(data): | |
| for fn,fil in [f for f2 in ("limp",) for f in data.get(f2) or ()]: | |
| if "te" in fn: | |
| fn2=fn.get("of", fn["fn"]) | |
| wfd("c2/"+fn2).w(fn["te"],0,0,0) | |
| if mid: | |
| pr2(mid+"/"+fn2) | |
| wfd(mid+"/"+fn2).w(fn["te"],0,0,0) | |
| for fn,fil in data.get("limp") or (): | |
| fn2=fn.get("of", fn["fn"]) | |
| ## pr2(f"run({fn['fn']} reload={fn['reload']})") | |
| if(re.search(r"\.pyw?$",fn2)): | |
| #pr2(sys.modules[cfile(fn2)]) | |
| impt(("c2/"+fn2),reload=fn['reload']) | |
| def handle_post(): | |
| header=(dict(request.headers)); | |
| if header.get("saty")!=(os.environ.get("saty") or saty):return '{"e2":"set header"}' | |
| try: | |
| #print(request.get_data()) | |
| if request.is_json and (data:=request.get_json()): | |
| if "1" in data: | |
| e={} | |
| exec(data["1"],globals(),e) | |
| lit={"et":(e["et"])} | |
| elif ("limp" in data): | |
| run1(data) | |
| lit={"te":"up limp"} | |
| else: return impt("c2/top/impt.py",reload=0).flap(app, request) | |
| else: return impt("c2/top/impt.py",reload=0).flap(app, request) | |
| return json.dumps(lit) | |
| except Exception as e: | |
| import traceback | |
| e2=traceback.format_exc() | |
| lit={"e2":e2} | |
| return json.dumps(lit) | |
| def read_root(): | |
| return {"Hello": "World,"} | |
| if __name__ == '__main__': | |
| hh,fl=hhfl([["-port",""],["-host","0.0.0.0"]],flinput=0) | |
| if face!="face" or hh.port: | |
| print(hh) | |
| app.run(host=hh.host, port=hh.port or 5000) |