deo / app.py
jinyin3's picture
Update app.py
14709fc verified
import gradio as gr
import os
from main_infer import INFER_API
def process_image(image):
# 设置保存图片的路径,指向当前工程的 images 目录
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)
infer_api = INFER_API()
score = infer_api.test(image_path)
return score # 返回保存的位置信息
# 定义输入:一个图片选择框
image_input = gr.components.Image(label="Upload Image", type="pil")
# 定义输出:一个文本框,用来显示确认信息或处理结果
text_output = gr.components.Textbox()
# 创建 Interface 对象,设置 live=False 以添加提交按钮
demo = gr.Interface(fn=process_image, inputs=image_input, outputs=text_output, live=False)
# 启动界面
demo.launch()