Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,8 +7,9 @@ import requests
|
|
| 7 |
from io import BytesIO
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
| 10 |
-
CORS(app)
|
| 11 |
|
|
|
|
| 12 |
model = load_model("model/Model_CNN_256px.keras")
|
| 13 |
|
| 14 |
class_labels = {
|
|
@@ -22,10 +23,10 @@ class_labels = {
|
|
| 22 |
def predict():
|
| 23 |
data = request.json
|
| 24 |
image_url = data.get("image_url")
|
| 25 |
-
|
| 26 |
if not image_url:
|
| 27 |
return jsonify({"error": "image_url missing"}), 400
|
| 28 |
|
|
|
|
| 29 |
response = requests.get(image_url)
|
| 30 |
img = Image.open(BytesIO(response.content)).convert("RGB")
|
| 31 |
img = img.resize((256, 256))
|
|
@@ -40,17 +41,6 @@ def predict():
|
|
| 40 |
"akurasi": round(float(preds[0][idx]) * 100, 2)
|
| 41 |
})
|
| 42 |
|
| 43 |
-
@app.route("/")
|
| 44 |
-
def home():
|
| 45 |
-
return jsonify({"message": "API Bertani running"})
|
| 46 |
-
|
| 47 |
@app.route("/health")
|
| 48 |
def health():
|
| 49 |
-
return {"status": "ok"}
|
| 50 |
-
|
| 51 |
-
if __name__ == "__main__":
|
| 52 |
-
app.run(
|
| 53 |
-
host="0.0.0.0",
|
| 54 |
-
port=7860,
|
| 55 |
-
debug=False
|
| 56 |
-
)
|
|
|
|
| 7 |
from io import BytesIO
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
| 10 |
+
CORS(app) # biar bisa diakses dari frontend
|
| 11 |
|
| 12 |
+
# Load model
|
| 13 |
model = load_model("model/Model_CNN_256px.keras")
|
| 14 |
|
| 15 |
class_labels = {
|
|
|
|
| 23 |
def predict():
|
| 24 |
data = request.json
|
| 25 |
image_url = data.get("image_url")
|
|
|
|
| 26 |
if not image_url:
|
| 27 |
return jsonify({"error": "image_url missing"}), 400
|
| 28 |
|
| 29 |
+
# Preprocess gambar
|
| 30 |
response = requests.get(image_url)
|
| 31 |
img = Image.open(BytesIO(response.content)).convert("RGB")
|
| 32 |
img = img.resize((256, 256))
|
|
|
|
| 41 |
"akurasi": round(float(preds[0][idx]) * 100, 2)
|
| 42 |
})
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
@app.route("/health")
|
| 45 |
def health():
|
| 46 |
+
return jsonify({"status": "ok"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|