Spaces:
Runtime error
Runtime error
File size: 1,225 Bytes
3ff00f1 5f7a3da 3ff00f1 f3b4b4b 3ff00f1 dc02d41 16bc34a 3ff00f1 5a7f292 |
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 |
from flask import Flask, request, jsonify
from PIL import Image
import base64
from io import BytesIO
import io
from SegCloth import segment_clothing
# CrΓ©er une instance FastAPI
app = Flask(__name__)
def segment_image(img, clothes):
img = decode_image_from_base64(img)
return segment_clothing(img, clothes)
# Fonction pour dΓ©coder une image encodΓ©e en base64 en objet PIL.Image.Image
def decode_image_from_base64(image_data):
image_data = base64.b64decode(image_data)
image = Image.open(io.BytesIO(image_data))
return image
def encode_image_to_base64(image):
buffered = BytesIO()
image.save(buffered, format="PNG")
return base64.b64encode(buffered.getvalue()).decode('utf-8')
@app.get("/")
def root():
return "Welcome to Fashion Clothing Detectiony API!"
# Route pour l'API REST
@app.route('/api/classify', methods=['POST'])
def classify():
data = request.json
print(data)
clothes = ["Hat", "Upper-clothes", "Skirt", "Pants", "Dress", "Belt", "Left-shoe", "Right-shoe", "Scarf"]
image = data['image']
result = segment_image(image,clothes)
return jsonify({'result': result})
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=7860) |