Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -176,6 +176,7 @@ def encode_image_to_base64(image):
|
|
176 |
buffered = BytesIO()
|
177 |
image.save(buffered, format="PNG") # Use PNG for compatibility with RGBA
|
178 |
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
|
|
179 |
@spaces.GPU
|
180 |
def rm_background(image):
|
181 |
im = load_img(image, output_type="pil")
|
@@ -204,7 +205,8 @@ def remove_background(image):
|
|
204 |
else:
|
205 |
raise TypeError("Unsupported image type")
|
206 |
return output
|
207 |
-
|
|
|
208 |
def detect_and_segment_persons(image, clothes):
|
209 |
img = np.array(image)
|
210 |
img = img[:, :, ::-1] # RGB -> BGR
|
@@ -272,5 +274,14 @@ def get_image(image_id):
|
|
272 |
except FileNotFoundError:
|
273 |
return jsonify({'error': 'Image not found'}), 404
|
274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
if __name__ == "__main__":
|
|
|
|
|
276 |
app.run(debug=True, host="0.0.0.0", port=7860)
|
|
|
176 |
buffered = BytesIO()
|
177 |
image.save(buffered, format="PNG") # Use PNG for compatibility with RGBA
|
178 |
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
179 |
+
|
180 |
@spaces.GPU
|
181 |
def rm_background(image):
|
182 |
im = load_img(image, output_type="pil")
|
|
|
205 |
else:
|
206 |
raise TypeError("Unsupported image type")
|
207 |
return output
|
208 |
+
|
209 |
+
@spaces.GPU
|
210 |
def detect_and_segment_persons(image, clothes):
|
211 |
img = np.array(image)
|
212 |
img = img[:, :, ::-1] # RGB -> BGR
|
|
|
274 |
except FileNotFoundError:
|
275 |
return jsonify({'error': 'Image not found'}), 404
|
276 |
|
277 |
+
def initialize_model_in_subprocess():
|
278 |
+
# Charger le modèle avec le GPU ici
|
279 |
+
model = torch.hub.load("pytorch/vision:v0.10.0", "resnet18", pretrained=True)
|
280 |
+
model = model.to("cuda")
|
281 |
+
return model
|
282 |
+
|
283 |
+
|
284 |
if __name__ == "__main__":
|
285 |
+
with multiprocessing.Pool(1) as pool:
|
286 |
+
model = pool.apply(initialize_model_in_subprocess)
|
287 |
app.run(debug=True, host="0.0.0.0", port=7860)
|