File size: 1,534 Bytes
a3fc548
 
 
 
 
 
86c4181
a3fc548
 
86c4181
a3fc548
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, request, jsonify
import shutil
import os
from werkzeug.utils import secure_filename
from application import *
from functions import *
from flask_cors import CORS

app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
# 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
@app.route('/upload/', methods=['POST'])
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)