Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
183a1ff
1
Parent(s):
d4dcfc5
修复页面显示错误问题:优化错误消息处理和UI显示
Browse files
app.py
CHANGED
@@ -882,10 +882,12 @@ if IN_HF_SPACE and 'spaces' in globals():
|
|
882 |
if flag == 'file':
|
883 |
output_filename = data
|
884 |
prev_output_filename = output_filename
|
885 |
-
|
|
|
886 |
|
887 |
if flag == 'progress':
|
888 |
preview, desc, html = data
|
|
|
889 |
yield gr.update(), gr.update(visible=True, value=preview), desc, html, gr.update(interactive=False), gr.update(interactive=True)
|
890 |
|
891 |
if flag == 'error':
|
@@ -903,6 +905,7 @@ if IN_HF_SPACE and 'spaces' in globals():
|
|
903 |
error_html = create_error_html(error_message)
|
904 |
yield output_filename, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
905 |
else:
|
|
|
906 |
yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
|
907 |
break
|
908 |
except Exception as e:
|
@@ -956,10 +959,12 @@ else:
|
|
956 |
if flag == 'file':
|
957 |
output_filename = data
|
958 |
prev_output_filename = output_filename
|
959 |
-
|
|
|
960 |
|
961 |
if flag == 'progress':
|
962 |
preview, desc, html = data
|
|
|
963 |
yield gr.update(), gr.update(visible=True, value=preview), desc, html, gr.update(interactive=False), gr.update(interactive=True)
|
964 |
|
965 |
if flag == 'error':
|
@@ -977,6 +982,7 @@ else:
|
|
977 |
error_html = create_error_html(error_message)
|
978 |
yield output_filename, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
979 |
else:
|
|
|
980 |
yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
|
981 |
break
|
982 |
except Exception as e:
|
@@ -1137,7 +1143,40 @@ def make_custom_css():
|
|
1137 |
padding: 10px;
|
1138 |
border-radius: 4px;
|
1139 |
margin-top: 10px;
|
|
|
|
|
|
|
|
|
1140 |
background-color: rgba(255, 0, 0, 0.1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1141 |
}
|
1142 |
"""
|
1143 |
|
@@ -1454,8 +1493,8 @@ with block:
|
|
1454 |
progress_desc = gr.Markdown('', elem_classes='no-generating-animation')
|
1455 |
progress_bar = gr.HTML('', elem_classes='no-generating-animation')
|
1456 |
|
1457 |
-
# 错误信息区域
|
1458 |
-
error_message = gr.
|
1459 |
|
1460 |
# 处理函数
|
1461 |
ips = [input_image, prompt, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache]
|
@@ -1500,22 +1539,32 @@ def create_error_html(error_msg, is_timeout=False):
|
|
1500 |
en_msg = f"Processing error: {error_msg}"
|
1501 |
zh_msg = f"处理过程出错: {error_msg}"
|
1502 |
|
1503 |
-
# 创建双语错误消息HTML
|
1504 |
return f"""
|
1505 |
-
<div
|
1506 |
-
<div class="error-msg-en" data-lang="en">
|
1507 |
-
|
|
|
|
|
|
|
|
|
1508 |
</div>
|
1509 |
<script>
|
1510 |
// 根据当前语言显示相应的错误消息
|
1511 |
(function() {{
|
1512 |
-
const errorContainer = document.getElementById('error-container');
|
1513 |
if (errorContainer) {{
|
1514 |
const currentLang = window.currentLang || 'en'; // 默认英语
|
1515 |
const errMsgs = errorContainer.querySelectorAll('[data-lang]');
|
1516 |
errMsgs.forEach(msg => {{
|
1517 |
msg.style.display = msg.getAttribute('data-lang') === currentLang ? 'block' : 'none';
|
1518 |
}});
|
|
|
|
|
|
|
|
|
|
|
|
|
1519 |
}}
|
1520 |
}})();
|
1521 |
</script>
|
|
|
882 |
if flag == 'file':
|
883 |
output_filename = data
|
884 |
prev_output_filename = output_filename
|
885 |
+
# 清除错误显示,确保文件成功时不显示错误
|
886 |
+
yield output_filename, gr.update(), gr.update(), '', gr.update(interactive=False), gr.update(interactive=True)
|
887 |
|
888 |
if flag == 'progress':
|
889 |
preview, desc, html = data
|
890 |
+
# 更新进度时不改变错误信息
|
891 |
yield gr.update(), gr.update(visible=True, value=preview), desc, html, gr.update(interactive=False), gr.update(interactive=True)
|
892 |
|
893 |
if flag == 'error':
|
|
|
905 |
error_html = create_error_html(error_message)
|
906 |
yield output_filename, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
907 |
else:
|
908 |
+
# 确保成功完成时不显示任何错误
|
909 |
yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
|
910 |
break
|
911 |
except Exception as e:
|
|
|
959 |
if flag == 'file':
|
960 |
output_filename = data
|
961 |
prev_output_filename = output_filename
|
962 |
+
# 清除错误显示,确保文件成功时不显示错误
|
963 |
+
yield output_filename, gr.update(), gr.update(), '', gr.update(interactive=False), gr.update(interactive=True)
|
964 |
|
965 |
if flag == 'progress':
|
966 |
preview, desc, html = data
|
967 |
+
# 更新进度时不改变错误信息
|
968 |
yield gr.update(), gr.update(visible=True, value=preview), desc, html, gr.update(interactive=False), gr.update(interactive=True)
|
969 |
|
970 |
if flag == 'error':
|
|
|
982 |
error_html = create_error_html(error_message)
|
983 |
yield output_filename, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
984 |
else:
|
985 |
+
# 确保成功完成时不显示任何错误
|
986 |
yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
|
987 |
break
|
988 |
except Exception as e:
|
|
|
1143 |
padding: 10px;
|
1144 |
border-radius: 4px;
|
1145 |
margin-top: 10px;
|
1146 |
+
}
|
1147 |
+
|
1148 |
+
/* 确保错误容器正确显示 */
|
1149 |
+
.error-message {
|
1150 |
background-color: rgba(255, 0, 0, 0.1);
|
1151 |
+
padding: 10px;
|
1152 |
+
border-radius: 4px;
|
1153 |
+
margin-top: 10px;
|
1154 |
+
border: 1px solid #ffcccc;
|
1155 |
+
}
|
1156 |
+
|
1157 |
+
/* 处理多语言错误消息 */
|
1158 |
+
.error-msg-en, .error-msg-zh {
|
1159 |
+
font-weight: bold;
|
1160 |
+
}
|
1161 |
+
|
1162 |
+
/* 错误图标 */
|
1163 |
+
.error-icon {
|
1164 |
+
color: #ff4444;
|
1165 |
+
font-size: 18px;
|
1166 |
+
margin-right: 8px;
|
1167 |
+
}
|
1168 |
+
|
1169 |
+
/* 确保空错误消息不显示背景和边框 */
|
1170 |
+
#error-message:empty {
|
1171 |
+
background-color: transparent;
|
1172 |
+
border: none;
|
1173 |
+
padding: 0;
|
1174 |
+
margin: 0;
|
1175 |
+
}
|
1176 |
+
|
1177 |
+
/* 修复Gradio默认错误显示 */
|
1178 |
+
.error {
|
1179 |
+
display: none !important;
|
1180 |
}
|
1181 |
"""
|
1182 |
|
|
|
1493 |
progress_desc = gr.Markdown('', elem_classes='no-generating-animation')
|
1494 |
progress_bar = gr.HTML('', elem_classes='no-generating-animation')
|
1495 |
|
1496 |
+
# 错误信息区域 - 确保使用HTML组件以支持我们的自定义错误消息格式
|
1497 |
+
error_message = gr.HTML('', elem_id='error-message', visible=True)
|
1498 |
|
1499 |
# 处理函数
|
1500 |
ips = [input_image, prompt, n_prompt, seed, total_second_length, latent_window_size, steps, cfg, gs, rs, gpu_memory_preservation, use_teacache]
|
|
|
1539 |
en_msg = f"Processing error: {error_msg}"
|
1540 |
zh_msg = f"处理过程出错: {error_msg}"
|
1541 |
|
1542 |
+
# 创建双语错误消息HTML - 添加有用的图标并确保CSS样式适用
|
1543 |
return f"""
|
1544 |
+
<div class="error-message" id="custom-error-container">
|
1545 |
+
<div class="error-msg-en" data-lang="en">
|
1546 |
+
<span class="error-icon">⚠️</span> {en_msg}
|
1547 |
+
</div>
|
1548 |
+
<div class="error-msg-zh" data-lang="zh">
|
1549 |
+
<span class="error-icon">⚠️</span> {zh_msg}
|
1550 |
+
</div>
|
1551 |
</div>
|
1552 |
<script>
|
1553 |
// 根据当前语言显示相应的错误消息
|
1554 |
(function() {{
|
1555 |
+
const errorContainer = document.getElementById('custom-error-container');
|
1556 |
if (errorContainer) {{
|
1557 |
const currentLang = window.currentLang || 'en'; // 默认英语
|
1558 |
const errMsgs = errorContainer.querySelectorAll('[data-lang]');
|
1559 |
errMsgs.forEach(msg => {{
|
1560 |
msg.style.display = msg.getAttribute('data-lang') === currentLang ? 'block' : 'none';
|
1561 |
}});
|
1562 |
+
|
1563 |
+
// 确保Gradio默认错误UI不显示
|
1564 |
+
const defaultErrorElements = document.querySelectorAll('.error');
|
1565 |
+
defaultErrorElements.forEach(el => {{
|
1566 |
+
el.style.display = 'none';
|
1567 |
+
}});
|
1568 |
}}
|
1569 |
}})();
|
1570 |
</script>
|