-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
44 lines (34 loc) · 1.22 KB
/
app.py
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
from flask import Flask, request, jsonify
from flask_cors import CORS
import disease_detector
import json
app = Flask(__name__)
CORS(app) # Enable CORS for all routes
# Loading disease_info.json
with open('disease_info.json', 'r') as file:
dataset_info = json.load(file)
@app.route('/', methods=['POST'])
def display_disease():
if 'image' not in request.files:
return jsonify({"error": "No image provided"})
image_file = request.files['image']
if image_file.filename == '':
return jsonify({"error": "No image selected"})
image_path = 'temp.jpg' # Temporary file path
image_file.save(image_path)
# Performing disease detection
model_prediction = disease_detector.predict_disease_from_image(image_path)
# Retrieving information about the predicted disease
disease_info = dataset_info.get(model_prediction, {})
# Preparing response
result = {
"disease": {
"class": model_prediction,
"name": disease_info.get('name', ''),
"symptoms": disease_info.get('symptoms', ''),
"management": disease_info.get('management', '')
}
}
return jsonify(result)
if __name__ == '__main__':
app.run(debug=True, port=3000)