Spaces:
Sleeping
Sleeping
from flask import Flask, request, jsonify | |
import shutil | |
import os | |
from werkzeug.utils import secure_filename | |
from application import * | |
from functions import * | |
app = Flask(__name__) | |
# Fotoğraf özellikleri | |
heightImg = 300 * 4 | |
widthImg = 210 * 4 | |
questions = 25 | |
choices = 6 | |
a1 = functions.read_answers("answers/test1-1.txt") | |
a2 = functions.answers2numbers(a1) | |
a3 = functions.read_answers("answers/test1-2.txt") | |
a4 = functions.answers2numbers(a3) | |
a5 = functions.read_answers("answers/test1-3.txt") | |
a6 = functions.answers2numbers(a5) | |
a7 = functions.read_answers("answers/test1-4.txt") | |
a8 = functions.answers2numbers(a7) | |
# Upload endpoint | |
def upload_image(): | |
try: | |
# Upload received file to a directory | |
upload_dir = "uploads" | |
os.makedirs(upload_dir, exist_ok=True) | |
file = request.files['image'] | |
filename = secure_filename(file.filename) | |
file.save(os.path.join(upload_dir, filename)) | |
# Process the uploaded image (you can replace this with your processing function) | |
result = optic1( | |
ans_txt1=a2, | |
ans_txt2=a4, | |
ans_txt3=a6, | |
ans_txt4=a8, | |
pathImage=os.path.join(upload_dir, filename) | |
) | |
# Return result as JSON | |
return jsonify(result) | |
except Exception as e: | |
return jsonify({"error": str(e)}) | |
if __name__ == '__main__': | |
app.run(host="0.0.0.0", port=8000) | |