Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,22 @@
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
-
# Hugging Face modelini yüklüyoruz (tek seferlik)
|
| 9 |
classifier = pipeline("image-classification", model="ahmed792002/vit-plant-classification")
|
| 10 |
|
| 11 |
-
@app.route(
|
| 12 |
-
def home():
|
| 13 |
-
return "Lumi çalışıyor 🌿"
|
| 14 |
-
|
| 15 |
-
@app.route("/predict", methods=["POST"])
|
| 16 |
def predict():
|
| 17 |
if 'image' not in request.files:
|
| 18 |
-
return jsonify({
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
results = classifier(image)
|
| 24 |
-
# En yüksek olasılıklı sonucu al
|
| 25 |
-
best = results[0]
|
| 26 |
-
label = best["label"]
|
| 27 |
-
score = round(best["score"] * 100, 2)
|
| 28 |
|
| 29 |
-
return jsonify({
|
| 30 |
-
"bitkiAdi": label,
|
| 31 |
-
"tahminOrani": f"%{score}"
|
| 32 |
-
})
|
| 33 |
-
except Exception as e:
|
| 34 |
-
return jsonify({"error": str(e)}), 500
|
| 35 |
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Önemli: huggingface hub cache dizinini değiştir
|
| 6 |
+
os.environ['HF_HOME'] = '/tmp/huggingface'
|
| 7 |
+
os.environ['TRANSFORMERS_CACHE'] = '/tmp/transformers'
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
| 10 |
|
|
|
|
| 11 |
classifier = pipeline("image-classification", model="ahmed792002/vit-plant-classification")
|
| 12 |
|
| 13 |
+
@app.route('/predict', methods=['POST'])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def predict():
|
| 15 |
if 'image' not in request.files:
|
| 16 |
+
return jsonify({'error': 'No image uploaded'}), 400
|
| 17 |
|
| 18 |
+
image = request.files['image']
|
| 19 |
+
predictions = classifier(image)
|
| 20 |
+
return jsonify(predictions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|