nontGcob's picture
releasing the app to the public
1728ec4
from flask import Flask, render_template, request, send_file
from urllib.parse import quote as url_quote
from model import model
app = Flask(__name__)
@app.route('/process', methods=['POST'])
def process():
T2E_exam = str(request.remote_addr) + ".txt"
text = request.form['text']
cefr_level = request.form['cefr_level']
# Call your Python function here to process the data
output = model(text, cefr_level)
user_data = {cefr_level: text}
with open("user_data_log.txt", "a") as file:
file.write(str(user_data) + "\n\n")
# Save the output to a file
count = 0
max_choice = 4
with open(T2E_exam, "w") as file:
file.write("__________ T2E Vocabulary Exam Generator __________\n")
file.write("| Welcome to T2E Vocabulary Exam Generator! |\n")
file.write("| We are glad that our service is useful to you. |\n")
file.write("| |\n")
file.write("| Copyrights 2023, Nutnornont Chamadol |\n")
file.write("| Email: nontc49@gmail.com |\n")
file.write("| Visit https://nontgcob.com to learn more |\n")
file.write("| |\n")
file.write("| Your exam is generated below. |\n")
file.write("| - Happy using T2E Vocabulary Exam Generator! - |\n")
file.write("|__________________________________________________|\n")
file.write("\n")
file.write("If you don't see any text on the Result page, try changing ")
file.write("the CEFR difficulty level selected or choose ALL CEFR level ")
file.write("to make sure you get all the questions that the AI can generate. ")
file.write("Another possible reason why nothing comes out of the program is ")
file.write("because there is no word that can be turned into an exam, try ")
file.write("putting a longer text passage as an input into the textbox instead.\n")
file.write("Visit https://scribehow.com/shared/How_to_use_T2E_Vocabulary_Exam_Generator__vyYu396JT_qZ0jKATVUqeQ#89cd5f52 for more information.\n")
file.write("\n")
file.write("Note: The first choice of each question is the correct answer, the rest are trick choices!\n")
file.write("\n")
file.write("\n")
for key, value in output.items():
vvocab, sentence = key.split(" = ")
# print(f'What does the word "{vvocab}" means in this sentence "{sentence}"?')
with open(T2E_exam, "a") as file:
file.write(f'What is the meaning of the word "{vvocab}" in this sentence "{sentence}"?\n')
for choice in value:
# print(f"- {choice}")
with open(T2E_exam, "a") as file:
file.write(f"- {choice}\n")
count += 1
# if count > (max_choice + 1):
# break
with open(T2E_exam, "a") as file:
file.write("\n")
# print("output:", output)
# print(type(output))
return render_template('result.html', output=output, file_path="T2E_exam.txt")
@app.route('/')
def index():
return render_template('index.html')
@app.route('/send')
def get_file():
T2E_exam = str(request.remote_addr) + ".txt"
return send_file(
str(request.remote_addr) + ".txt",
# download_name = "T2E_exam.txt"
)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=7860)