Rooni's picture
Create app.py
1fae4f7 verified
raw
history blame
1.75 kB
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()