siranida commited on
Commit
d6f3498
·
verified ·
1 Parent(s): 470c555

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -40
app.py DELETED
@@ -1,40 +0,0 @@
1
- from flask import Flask, request, jsonify
2
- from transformers import pipeline
3
- from PIL import Image
4
- import io
5
-
6
- # Flask uygulaması
7
- app = Flask(__name__)
8
-
9
- # Hugging Face model pipeline'ı (image classification)
10
- classifier = pipeline("image-classification", model="umutbozdag/plant-identity")
11
-
12
- # API endpoint
13
- @app.route("/predict", methods=["POST"])
14
- def predict():
15
- if 'file' not in request.files:
16
- return jsonify({"error": "No file uploaded"}), 400
17
-
18
- try:
19
- # Dosyayı oku ve PIL Image objesine dönüştür
20
- image_file = request.files['file']
21
- image_bytes = image_file.read()
22
- image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
23
-
24
- # Model ile tahmin yap
25
- result = classifier(image)
26
-
27
- # En yüksek olasılığa sahip etiketi al
28
- top_result = result[0]["label"] if result else "No prediction"
29
-
30
- return jsonify({"label": top_result})
31
- except Exception as e:
32
- return jsonify({"error": str(e)}), 500
33
-
34
-
35
- @app.route("/", methods=["GET"])
36
- def home():
37
- return "Bitki Tanıma API - Lumi 🌿"
38
-
39
- if __name__ == "__main__" and os.getenv("HF_SPACE") != "1":
40
- app.run(host="0.0.0.0", port=7860)