CoolFace
Apppublic

Thenujan/VPR_deploy

sourceHugging Faceotherupdated 3y agoView on Hugging Face
0likes
app.py63 linesDownload Raw Back to root
1import os2import similarity_search3import gradio as gr4 5# Path to the directory containing similar images6# similar_images_dir = ".\gallery"7 8# def read_image(image_file):9#     img = cv2.imread(10#         image_file, cv2.IMREAD_COLOR | cv2.IMREAD_IGNORE_ORIENTATION11#     )12#     img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)13#     if img is None:14#         raise ValueError('Failed to read {}'.format(image_file))15#     return img16 17def get_similar_images(image):18    similar_image_ids = similarity_search.find(image)19    return similar_image_ids20 21 22# def get_image_paths(prod_ids):23#     csv_path = './gallery.csv'  # Replace with the actual path24#     data = pd.read_csv(csv_path)25#     image_paths = []26 27#     for i, prod_id in enumerate(prod_ids):28#         row = data[data['seller_img_id'] == prod_id]29        30#         if not row.empty:31#             image_path = './' + row.iloc[0]['img_path']32#             print(image_path)33#             image_paths.append(image_path)34 35#     return image_paths36 37 38def predict(image):39 40    similar_image_ids = get_similar_images(image)41 42    return {"similar_image_ids" : similar_image_ids}43 44# Create title, description and article strings45title = "Visual Product Recognition"46description = "A model to find the similar images in the e-commerce platform"47article = "Created by Thenujan Nagaratnam for Data Science Project at UoM"48 49# Create examples list from "examples/" directory50example_list = [["examples/" + example] for example in os.listdir("examples")]51 52# Create the Gradio demo53demo = gr.Interface(fn=predict, # mapping function from input to output54                    inputs=gr.Image(type="pil"), # what are the inputs?55                    outputs=gr.JSON(label="Predictions"),56                    examples=example_list, 57                    title=title,58                    description=description,59                    article=article)60 61 62# Launch the demo!63demo.launch()