Spaces:
Runtime error
Runtime error
import os | |
os.system("pip install xtcocotools>=1.12") | |
os.system("pip install 'mmengine>=0.6.0'") | |
os.system("pip install 'mmcv>=2.0.0rc4,<2.1.0'") | |
os.system("pip install 'mmdet>=3.0.0,<4.0.0'") | |
os.system("pip install 'mmpose'") | |
from keypoints_extraction import predict_poses | |
from calculate_measures import calculate_all_measures | |
from calculate_masks import calculate_seg_mask | |
from select_body_shape import select_body_shape | |
import gradio as gr | |
def generate_output(front_img_path, side_img_path): | |
# TODO: These file names will need to be unique in case of multiple requests at once, and they will need to be deleted after the function is done. | |
keypoint_results = predict_poses(front_img_path, "front.jpg", side_img_path, "side.jpg") | |
front_keypoint_result = keypoint_results[0] | |
side_keypoint_result = keypoint_results[1] | |
front_image = front_keypoint_result[0] | |
side_image = side_keypoint_result[0] | |
front_keypoint_data = front_keypoint_result[1] | |
side_keypoint_data = side_keypoint_result[1] | |
front_seg_mask = calculate_seg_mask(front_img_path) | |
side_seg_mask = calculate_seg_mask(side_img_path) | |
measures_data_frame = calculate_all_measures(front_image, side_image, front_keypoint_data, side_keypoint_data, front_seg_mask, side_seg_mask) | |
# We can't normalise the measures because we don't have multiple images in this case, so just use the measures directly. | |
normalised_measures_data_frame = measures_data_frame | |
body_shape_result = select_body_shape(normalised_measures_data_frame) | |
selected_body_shape = body_shape_result[0] | |
calculation_information = body_shape_result[1] | |
return (selected_body_shape, calculation_information) | |
input_image_front = gr.inputs.Image(type='pil', label="Front Image") | |
input_image_side = gr.inputs.Image(type='pil', label="Side Image") | |
output_body_shape = gr.outputs.Textbox(label="Body Shape") | |
output_calculation_information = gr.outputs.Textbox(label="Calculation Information") | |
title = "ShopByShape" | |
iface = gr.Interface(fn=generate_output, inputs=[input_image_front, input_image_side], outputs=[output_body_shape, output_calculation_information], title=title) | |
iface.launch() | |