File size: 1,117 Bytes
719eddc
4334a37
070f7a9
 
719eddc
4334a37
 
 
 
 
 
 
 
 
 
 
 
 
 
070f7a9
402adb3
070f7a9
14709fc
719eddc
4334a37
070f7a9
e8b0040
4334a37
070f7a9
e8b0040
 
070f7a9
e8b0040
 
 
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
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()