|
import gradio as gr |
|
import os |
|
|
|
def process_image(image): |
|
|
|
save_path = os.path.join(os.getcwd(), "images") |
|
|
|
os.makedirs(save_path, exist_ok=True) |
|
|
|
|
|
from datetime import datetime |
|
timestamp = datetime.now().strftime("%Y%m%d%H%M%S") |
|
image_filename = f"uploaded_{timestamp}.png" |
|
image_path = os.path.join(save_path, image_filename) |
|
|
|
|
|
image.save(image_path) |
|
|
|
return f"图片已保存至 {image_path}" |
|
|
|
|
|
inputs = gr.inputs.Image(label="Upload Image", type="pil") |
|
|
|
|
|
outputs = gr.outputs.Textbox() |
|
|
|
|
|
demo = gr.Interface(fn=process_image, inputs=inputs, outputs=outputs, live=False) |
|
|
|
|
|
demo.launch() |
|
|