File size: 1,746 Bytes
1fae4f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import gradio as gr
from PIL import Image # Needed create blank "proxy image in the functions below


def dummy_process_image(image):
    """Заглушка для обработки изображения. Возвращает пустое изображение."""
    return Image.new("RGB", (256, 256), "white"),  Image.new("RGB", (256, 256), "black")


def dummy_process_url(url):

    """Заглушка для обработки URL. Возвращает пустое изображение."""
    return Image.new("RGB", (256, 256), "white"),  Image.new("RGB", (256, 256), "black")

def dummy_process_file(filepath):
    """Заглушка для обработки файла. Возвращает имя фиктивного файла."""
    return "dummy_output.png"


with gr.Blocks() as demo:
    with gr.Tab("Image Upload"):
        with gr.Row():
            image_upload = gr.Image(label="Upload an image")
            output_image = gr.Image(label="Processed Image", type="pil")
        image_upload.change(dummy_process_image, image_upload, output_image)


    with gr.Tab("URL Input"):
         with gr.Row():
            url_input = gr.Textbox(label="Paste an image URL")
            output_url = gr.Image(label="Processed Image from URL", type="pil")
         url_input.submit(dummy_process_url, url_input, output_url) # Or "submit"  is more appropriate for text inputs and not change.


    with gr.Tab("File Output"):
        with gr.Row():
            image_file_upload = gr.Image(label="Upload an image",  type ="filepath")
            output_file = gr.File(label="Output PNG File")
        image_file_upload.change(dummy_process_file, image_file_upload, output_file)

if __name__ == "__main__":
    demo.launch()