Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
-
from
|
2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
3 |
from transformers import AutoProcessor, CLIPModel
|
4 |
from PIL import Image
|
5 |
|
@@ -9,17 +8,8 @@ processor = AutoProcessor.from_pretrained("patrickjohncyh/fashion-clip")
|
|
9 |
|
10 |
|
11 |
# Créer une instance FastAPI
|
12 |
-
app =
|
13 |
|
14 |
-
origins = ["*"]
|
15 |
-
|
16 |
-
app.add_middleware(
|
17 |
-
CORSMiddleware,
|
18 |
-
allow_origins=origins,
|
19 |
-
allow_credentials=True,
|
20 |
-
allow_methods=["*"],
|
21 |
-
allow_headers=["*"],
|
22 |
-
)
|
23 |
|
24 |
# Définir la fonction pour la classification d'image avec du texte en entrée
|
25 |
def classify_image_with_text(text, image):
|
@@ -40,12 +30,15 @@ def classify_image_with_text(text, image):
|
|
40 |
async def root():
|
41 |
return {"message": "Welcome to the Fashion Clip API!"}
|
42 |
|
43 |
-
#
|
44 |
-
@app.
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
49 |
if __name__ == '__main__':
|
50 |
app.run(debug=True)
|
51 |
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
|
|
2 |
from transformers import AutoProcessor, CLIPModel
|
3 |
from PIL import Image
|
4 |
|
|
|
8 |
|
9 |
|
10 |
# Créer une instance FastAPI
|
11 |
+
app = Flask(__name__)
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Définir la fonction pour la classification d'image avec du texte en entrée
|
15 |
def classify_image_with_text(text, image):
|
|
|
30 |
async def root():
|
31 |
return {"message": "Welcome to the Fashion Clip API!"}
|
32 |
|
33 |
+
# Route pour l'API REST
|
34 |
+
@app.route('/api/classify', methods=['POST'])
|
35 |
+
def classify():
|
36 |
+
data = request.json
|
37 |
+
text = data['text']
|
38 |
+
image = data['image']
|
39 |
+
result = classify_image_with_text(text, image)
|
40 |
+
return jsonify({'result': result})
|
41 |
+
|
42 |
if __name__ == '__main__':
|
43 |
app.run(debug=True)
|
44 |
|