File size: 912 Bytes
244c30f
 
 
 
 
 
 
 
 
b1f58bf
244c30f
 
fc46700
 
 
 
 
 
b1f58bf
244c30f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a05617
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
from flask import Flask, request, jsonify
from flask_cors import CORS
import os
from werkzeug.utils import secure_filename
from utils import predict_image

app = Flask(__name__)
CORS(app)  # Allow cross-origin (Next.js ke Flask)

UPLOAD_FOLDER = "/tmp/uploads"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)

@app.route("/", methods=["GET"])
def home():
    return jsonify({
        "status": "API is running",
        "message": "Use POST /predict to classify batik"
    })

@app.route('/predict', methods=['POST'])
def predict():
    if 'file' not in request.files:
        return jsonify({'error': 'No file uploaded'}), 400

    file = request.files['file']
    filename = secure_filename(file.filename)
    filepath = os.path.join(UPLOAD_FOLDER, filename)
    file.save(filepath)

    result = predict_image(filepath)

    return jsonify(result)

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=7860)