Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,6 +27,7 @@ def start_process(input1, input2, shape0_str, shape1_str, input_suffix=".pth"):
|
|
27 |
global task_counter
|
28 |
task_counter += 1
|
29 |
task_id = task_counter
|
|
|
30 |
log = "转换过程非常慢,请耐心等待。显示文件列表不代表转换完成。如果未发生错误,转换结束会显示”任务完成“\n"
|
31 |
yield [], log
|
32 |
if input2 == None or input2.strip() == "":
|
@@ -95,7 +96,8 @@ def start_process(input1, input2, shape0_str, shape1_str, input_suffix=".pth"):
|
|
95 |
yield [], log
|
96 |
return
|
97 |
elif input1 is not None:
|
98 |
-
|
|
|
99 |
log += f"使用上传的文件: {file_path}\n"
|
100 |
print_log(task_id, input2, "使用上传文件", "开始")
|
101 |
yield [], log
|
@@ -105,6 +107,20 @@ def start_process(input1, input2, shape0_str, shape1_str, input_suffix=".pth"):
|
|
105 |
yield [], log
|
106 |
return
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
# 生成新文件夹用于暂存结果
|
109 |
output_folder = os.path.join(os.getcwd(), str(uuid.uuid4()))
|
110 |
os.makedirs(output_folder, exist_ok=True)
|
@@ -199,9 +215,11 @@ def start_process(input1, input2, shape0_str, shape1_str, input_suffix=".pth"):
|
|
199 |
if output == '' and process.poll() is not None:
|
200 |
break
|
201 |
if output:
|
202 |
-
#
|
203 |
if log_to_terminal:
|
204 |
print(output.strip())
|
|
|
|
|
205 |
returncode = process.poll()
|
206 |
if returncode != 0:
|
207 |
log += f"执行命令: {command} 失败,返回码: {returncode}\n"
|
|
|
27 |
global task_counter
|
28 |
task_counter += 1
|
29 |
task_id = task_counter
|
30 |
+
print_log(task_id, input2, input1, "input1")
|
31 |
log = "转换过程非常慢,请耐心等待。显示文件列表不代表转换完成。如果未发生错误,转换结束会显示”任务完成“\n"
|
32 |
yield [], log
|
33 |
if input2 == None or input2.strip() == "":
|
|
|
96 |
yield [], log
|
97 |
return
|
98 |
elif input1 is not None:
|
99 |
+
print("check file" , input1, os.path.exists(input1))
|
100 |
+
file_path = input1
|
101 |
log += f"使用上传的文件: {file_path}\n"
|
102 |
print_log(task_id, input2, "使用上传文件", "开始")
|
103 |
yield [], log
|
|
|
107 |
yield [], log
|
108 |
return
|
109 |
|
110 |
+
# 检查文件大小
|
111 |
+
try:
|
112 |
+
file_size = os.path.getsize(file_path) / 1024 /1024 # 转换为 KB
|
113 |
+
if file_size > 100 :
|
114 |
+
log += f"文件太大,建议 100MB 以内,当前文件大小为 {file_size } MB。\n"
|
115 |
+
print_log(task_id, input2, "文件太大("+ file_size +"MB)", "失败")
|
116 |
+
yield [], log
|
117 |
+
return
|
118 |
+
except Exception as e:
|
119 |
+
log += f"获取文件大小失败: {str(e)}\n"
|
120 |
+
print_log(task_id, input2, "检查文件大小", f"失败: {str(e)}")
|
121 |
+
yield [], log
|
122 |
+
return
|
123 |
+
|
124 |
# 生成新文件夹用于暂存结果
|
125 |
output_folder = os.path.join(os.getcwd(), str(uuid.uuid4()))
|
126 |
os.makedirs(output_folder, exist_ok=True)
|
|
|
215 |
if output == '' and process.poll() is not None:
|
216 |
break
|
217 |
if output:
|
218 |
+
#
|
219 |
if log_to_terminal:
|
220 |
print(output.strip())
|
221 |
+
log += output.strip() + '\n'
|
222 |
+
yield [], log
|
223 |
returncode = process.poll()
|
224 |
if returncode != 0:
|
225 |
log += f"执行命令: {command} 失败,返回码: {returncode}\n"
|