import os import cv2 import gradio as gr import numpy as np import random import time def tryon(person_img, garment_prompt, seed, randomize_seed): post_start_time = time.time() if person_img is None or garment_prompt.strip() == "": return None, None, "Empty image or prompt" if randomize_seed: seed = random.randint(0, MAX_SEED) # Create a copy of the person image to overlay text result_img = person_img.copy() # Convert the image to OpenCV format (if needed) if len(result_img.shape) == 2: # Convert grayscale to RGB result_img = cv2.cvtColor(result_img, cv2.COLOR_GRAY2RGB) # Set text position and properties text_position = (10, 30) font = cv2.FONT_HERSHEY_SIMPLEX font_scale = 1 font_color = (0, 255, 0) # Green color for the text thickness = 2 # Overlay the garment description text on the image cv2.putText(result_img, f'Garment: {garment_prompt}', text_position, font, font_scale, font_color, thickness, cv2.LINE_AA) post_end_time = time.time() print(f"post time used: {post_end_time - post_start_time}") # Return the resulting image, used seed, and success message return result_img, seed, "Success" MAX_SEED = 999999 example_path = os.path.join(os.path.dirname(__file__), 'assets') human_list = os.listdir(os.path.join(example_path, "human")) human_list_path = [os.path.join(example_path, "human", human) for human in human_list] css = """ #col-left { margin: 0 auto; max-width: 430px; } #col-mid { margin: 0 auto; max-width: 430px; } #col-right { margin: 0 auto; max-width: 430px; } #col-showcase { margin: 0 auto; max-width: 1100px; } #button { color: blue; } """ def load_description(fp): with open(fp, 'r', encoding='utf-8') as f: content = f.read() return content with gr.Blocks(css=css) as Tryon: gr.HTML(load_description("assets/title.md")) with gr.Row(): with gr.Column(elem_id="col-left"): gr.HTML("""