Spaces:
Sleeping
Sleeping
File size: 1,797 Bytes
96ea36d |
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 39 40 41 42 43 44 |
from flask import Flask, request, render_template
import os
import subprocess
app = Flask(__name__)
def call_chatgpt(prompt_file, input_text):
# Your actual function to call the ChatGPT API will go here
# For now, return a placeholder string
with open(prompt_file, 'r') as file:
prompt = file.read()
return f"Prompt: {prompt}\nInput: {input_text}"
def call_convert_script(input_text):
# Your actual function to call the script will go here
# For now, return a placeholder string
# Run the script and capture the output
process = subprocess.Popen(['python', '../convert_haml_to_py_code.py'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
output, error = process.communicate(input=input_text)
return output + error
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
input_text = request.form.get('InputTextbox', '')
script_text = request.form.get('ScriptTextbox', '')
haml_text = request.form.get('HAMLTextbox', '')
python_code_text = request.form.get('PythonCodeTextbox', '')
if 'TextToScriptButton' in request.form:
script_text = call_chatgpt('../prompts/text_to_audio_script.prompt', input_text)
elif 'ScriptToHAMLButton' in request.form:
haml_text = call_chatgpt('../prompts/audio_script_to_HAML.prompt', script_text)
elif 'HAMLToPythonCodeButton' in request.form:
python_code_text = call_convert_script(haml_text)
return render_template('index.html', haml_text=haml_text, python_code_text=python_code_text, script_text=script_text, input_text=input_text)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
|