txtoutcomp / app.py
WillemVH's picture
Update app.py
f44b94f verified
from flask import Flask, request
from threading import Thread
import subprocess
import time
app = Flask(__name__)
# Global variables to store the parsed values
last_cmd = ""
last_ex = ""
last_v = ""
@app.route('/')
def index():
return """
Endpoints:
/input?input=Put output from chatbot here !!\ Lookatlastpersontalking ~ (happy) V 100
and this gives you an output like this: Put output from chatbot here
and if you go to this page: /outcmd it gives you: Lookatlastpersontalking
and /outex gives: happy
and /v gives: 100
"""
@app.route('/input')
def process_input():
global last_cmd, last_ex, last_v
user_input = request.args.get('input', '')
# Split the input into parts
parts = user_input.split('!!\\')
main_output = parts[0].strip() if parts else ""
if len(parts) > 1:
remaining = parts[1]
# Split command, expression, and V value
cmd_parts = remaining.split('~')
last_cmd = cmd_parts[0].strip() if cmd_parts else ""
if len(cmd_parts) > 1:
ex_parts = cmd_parts[1].split('V')
last_ex = ex_parts[0].strip(' ()') if ex_parts else ""
if len(ex_parts) > 1:
last_v = ex_parts[1].strip()
return main_output
@app.route('/outcmd')
def get_cmd():
return last_cmd
@app.route('/outex')
def get_ex():
return last_ex
@app.route('/v')
def get_v():
return last_v
if __name__ == '__main__':
Thread(target=start_tunnel).start()
print("Starting server at http://localhost:5000")
app.run(host='0.0.0.0', port=5000)