icapp_space / app.py
gmshroff's picture
new flask-based server for running scripts on huggingface
620d08d
raw
history blame
897 Bytes
from flask import Flask,request,render_template
import os
app=Flask(__name__)
MESSAGED={'title':'Script Server',
'messageL':['script in "script" parameter or field of json input to /run will be run']}
@app.route('/run',methods=['GET','POST'])
def run_script():
script=''
# print(request.method)
print(request)
if request.method=='GET':
script=request.args.get('script')
print('I am in get')
elif request.method=='POST':
print('I am in post')
data=request.get_json()
if 'script' in data: script=data['script']
if script=='' or script is None: return 'INVALID'
os.system(script+' > ./out.txt')
with open('./out.txt','r') as f: output=f.read()
return output
@app.route('/',methods=['GET', 'POST'])
def home():
return render_template('home.html',messageD=MESSAGED)
if __name__=='__main__':
app.run()