Spaces:
Runtime error
Runtime error
File size: 1,377 Bytes
c455cc5 |
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 |
```python
from flask import Flask, render_template, request, jsonify
import os
from PIL import Image
import numpy as np
app = Flask(__name__)
# Define the HTML template for the Tree Counter page
@app.route('/')
def index():
return render_template('index.html')
# Define the API endpoint for uploading images
@app.route('/upload_image', methods=['POST'])
def upload_image():
image = request.files['image']
image.save('image.jpg')
img = Image.open('image.jpg')
width, height = img.size
if width > 1024 or height > 1024:
return jsonify({'message': 'Image is too large. Please crop it.'})
else:
# Simulate tree detection using YOLO8 model
# Replace this with actual model implementation
trees = np.random.randint(0, 100)
return jsonify({'message': f'Number of Trees: {trees}'})
# Define the API endpoint for cropping images
@app.route('/crop_image', methods=['POST'])
def crop_image():
image = request.files['image']
image.save('image.jpg')
img = Image.open('image.jpg')
width, height = img.size
# Simulate image cropping
# Replace this with actual image cropping implementation
cropped_img = img.crop((0, 0, 1024, 1024))
cropped_img.save('cropped_image.jpg')
return jsonify({'message': 'Image cropped successfully'})
if __name__ == '__main__':
app.run(debug=True)
``` |