Spaces:
Runtime error
Runtime error
File size: 3,461 Bytes
df9d3bd 9d085a8 1e9d5db 9d085a8 be55d90 9d085a8 b33571d 9d085a8 53cb6a3 9d085a8 f63f8bc 9d085a8 ca623b5 df9d3bd 9d085a8 df9d3bd 9d085a8 1e9d5db be3b0a5 df9d3bd |
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
from flask import Flask, render_template, request, send_file
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)
|