import gradio as gr from funcs import process_image def process_image_gradio(image_path, watermark_text, font_path, font_size, opacity, color, right_margin, bottom_margin): # Вызываем функцию process_image из funcs.py output_paths = process_image(image_path, "output", watermark_text, font_path.name, font_size, opacity, color, right_margin, bottom_margin) # Cover obj to json str generation_params_str = f"Watermark Text: {watermark_text}\nFont Size: {font_size}\nOpacity: {opacity}\nColor: {color}\nRight Margin: {right_margin}\nBottom Margin: {bottom_margin}" # Возвращаем путь к изображению с водяным знаком return output_paths[0], output_paths[1], generation_params_str # Определяем интерфейс с использованием Gradio with gr.Blocks() as demo: with gr.Row(): with gr.Column(): # Компоненты для настроек image = gr.Image(label="Upload Image", type="filepath") font_path = gr.File(label="Font Path, .ttf only", file_types=[".ttf"]) watermark_text = gr.Textbox(label="Watermark Text") font_size = gr.Slider(minimum=6, maximum=100, step=1, label="Font Size", value=30) opacity = gr.Slider(minimum=0, maximum=1, step=0.01, label="Opacity", value=0.5) color = gr.ColorPicker(label="Color",value="#000000") right_margin = gr.Slider(minimum=0, maximum=1, step=0.01, label="Right Margin", value=0.05) bottom_margin = gr.Slider(minimum=0, maximum=1, step=0.01, label="Bottom Margin", value=0.02) with gr.Column(): # Компонент для отображения результата process_button = gr.Button("Process Image") generation_params = gr.Textbox(label="Generation Parameters",interactive=False,show_copy_button=True) output_image = gr.Image(label="Output Image",interactive=False) output_mini = gr.Image(label="Output Image (Mini)",interactive=False) # Обработчик нажатия кнопки "Process Image" process_button.click(process_image_gradio, inputs=[image, watermark_text, font_path, font_size, opacity, color, right_margin, bottom_margin], outputs=[output_image,output_mini,generation_params]) # Запускаем интерфейс demo.queue() demo.launch()