Spaces:
Running
Running
chenyicheng commited on
Commit ·
beb9c27
1
Parent(s): 7b003a5
update app
Browse files
app.py
CHANGED
|
@@ -902,46 +902,50 @@ def _run_with_timeout(func, timeout: int, *args, **kwargs):
|
|
| 902 |
executor.shutdown(wait=False, cancel_futures=True)
|
| 903 |
|
| 904 |
|
|
|
|
|
|
|
| 905 |
def _render_progress_html(current_step: int, error: bool = False, detail_msg: str = "", est_time: int = 0) -> str:
|
| 906 |
-
"""
|
| 907 |
-
current_step: 0=Preview, 1=Plan, 2=Code Gen, 3=Execution, 4=Done
|
| 908 |
-
est_time: Estimated seconds for the current step animation
|
| 909 |
-
"""
|
| 910 |
steps = ["Data Preview", "Processing Plan", "Code Generation", "Code Execution"]
|
| 911 |
icons_html = '<div class="step-row">'
|
| 912 |
|
| 913 |
-
# 当前正在进行的步骤的进度条 HTML
|
| 914 |
active_progress_html = ""
|
| 915 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 916 |
for idx, name in enumerate(steps):
|
| 917 |
is_active = (idx == current_step)
|
| 918 |
-
|
| 919 |
if idx < current_step:
|
| 920 |
-
status_class = "done"
|
| 921 |
-
icon = "✓"
|
| 922 |
elif is_active:
|
| 923 |
if error:
|
| 924 |
-
status_class = "error"
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
status_class = "done"
|
| 928 |
-
icon = "✓"
|
| 929 |
else:
|
| 930 |
-
status_class = "active"
|
| 931 |
-
icon = "⋯"
|
| 932 |
-
# 如果是当前活跃状态且没有错误,生成进度条
|
| 933 |
if est_time > 0:
|
|
|
|
| 934 |
active_progress_html = f"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 935 |
<div style="margin-top: 10px; padding: 0 10%;">
|
| 936 |
<div class="progress-bar-container">
|
| 937 |
-
<div class="progress-bar-fill"
|
| 938 |
</div>
|
| 939 |
<div class="est-time-text">Est. time: ~{est_time}s</div>
|
| 940 |
</div>
|
| 941 |
"""
|
| 942 |
else:
|
| 943 |
-
status_class = ""
|
| 944 |
-
icon = str(idx + 1)
|
| 945 |
|
| 946 |
icons_html += f"""
|
| 947 |
<div class="step-item {status_class}">
|
|
@@ -953,10 +957,7 @@ def _render_progress_html(current_step: int, error: bool = False, detail_msg: st
|
|
| 953 |
icons_html += '<div class="step-arrow">➜</div>'
|
| 954 |
|
| 955 |
icons_html += '</div>'
|
| 956 |
-
|
| 957 |
text_html = f'<div class="step-status-text">{detail_msg}</div>'
|
| 958 |
-
|
| 959 |
-
# 将进度条插入到底部
|
| 960 |
return f'<div class="step-container">{icons_html}{active_progress_html}{text_html}</div>'
|
| 961 |
|
| 962 |
|
|
@@ -1948,53 +1949,40 @@ _CUSTOM_CSS = """
|
|
| 1948 |
.control-panel .gradio-dataframe { margin-top: 0 !important; margin-bottom: 0 !important; }
|
| 1949 |
.btn-row { display: flex; flex-direction: row; align-items: center; }
|
| 1950 |
|
| 1951 |
-
.info-box {
|
| 1952 |
-
background: #f0f9ff;
|
| 1953 |
-
border: 1px solid #bae6fd;
|
| 1954 |
-
color: #0369a1;
|
| 1955 |
-
padding: 12px 16px;
|
| 1956 |
-
border-radius: 8px;
|
| 1957 |
-
font-size: 0.85rem;
|
| 1958 |
-
line-height: 1.5;
|
| 1959 |
-
margin-bottom: 16px;
|
| 1960 |
-
box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
|
| 1961 |
-
}
|
| 1962 |
-
.info-box ul {
|
| 1963 |
-
margin: 4px 0 0 18px;
|
| 1964 |
-
padding: 0;
|
| 1965 |
-
}
|
| 1966 |
-
.info-box li {
|
| 1967 |
-
margin-bottom: 4px;
|
| 1968 |
-
}
|
| 1969 |
-
|
| 1970 |
-
/* === 新增: 进度条动画样式 === */
|
| 1971 |
.progress-bar-container {
|
| 1972 |
width: 100%;
|
| 1973 |
background-color: #f1f5f9;
|
| 1974 |
-
border-radius:
|
| 1975 |
-
height:
|
| 1976 |
margin-top: 8px;
|
| 1977 |
overflow: hidden;
|
| 1978 |
-
|
| 1979 |
}
|
| 1980 |
|
| 1981 |
.progress-bar-fill {
|
| 1982 |
height: 100%;
|
| 1983 |
-
background
|
| 1984 |
width: 0%;
|
| 1985 |
-
border-radius: 4px;
|
| 1986 |
-
/* 动画名称,时长由内联样式控制 */
|
| 1987 |
-
animation-name: progressFill;
|
| 1988 |
-
animation-timing-function: linear;
|
| 1989 |
-
animation-fill-mode: forwards;
|
| 1990 |
}
|
| 1991 |
|
| 1992 |
.est-time-text {
|
| 1993 |
-
font-size: 0.
|
| 1994 |
-
color: #
|
| 1995 |
margin-top: 4px;
|
| 1996 |
-
text-align:
|
| 1997 |
-
font-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1998 |
}
|
| 1999 |
|
| 2000 |
@keyframes progressFill {
|
|
|
|
| 902 |
executor.shutdown(wait=False, cancel_futures=True)
|
| 903 |
|
| 904 |
|
| 905 |
+
import time # 确保开头导入了 time
|
| 906 |
+
|
| 907 |
def _render_progress_html(current_step: int, error: bool = False, detail_msg: str = "", est_time: int = 0) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 908 |
steps = ["Data Preview", "Processing Plan", "Code Generation", "Code Execution"]
|
| 909 |
icons_html = '<div class="step-row">'
|
| 910 |
|
|
|
|
| 911 |
active_progress_html = ""
|
| 912 |
|
| 913 |
+
# 生成一个唯一的 ID 和 动画名,确保每次切换步骤时浏览器都会重置动画
|
| 914 |
+
unique_id = f"step_bar_{current_step}_{int(time.time())}"
|
| 915 |
+
anim_name = f"fill_{unique_id}"
|
| 916 |
+
|
| 917 |
for idx, name in enumerate(steps):
|
| 918 |
is_active = (idx == current_step)
|
|
|
|
| 919 |
if idx < current_step:
|
| 920 |
+
status_class, icon = "done", "✓"
|
|
|
|
| 921 |
elif is_active:
|
| 922 |
if error:
|
| 923 |
+
status_class, icon = "error", "✕"
|
| 924 |
+
elif current_step == 4:
|
| 925 |
+
status_class, icon = "done", "✓"
|
|
|
|
|
|
|
| 926 |
else:
|
| 927 |
+
status_class, icon = "active", "⋯"
|
|
|
|
|
|
|
| 928 |
if est_time > 0:
|
| 929 |
+
# 通过内联 style 定义一个新的 keyframes 动画
|
| 930 |
active_progress_html = f"""
|
| 931 |
+
<style>
|
| 932 |
+
@keyframes {anim_name} {{
|
| 933 |
+
0% {{ width: 0%; }}
|
| 934 |
+
100% {{ width: 98%; }}
|
| 935 |
+
}}
|
| 936 |
+
#{unique_id} {{
|
| 937 |
+
animation: {anim_name} {est_time}s linear forwards;
|
| 938 |
+
}}
|
| 939 |
+
</style>
|
| 940 |
<div style="margin-top: 10px; padding: 0 10%;">
|
| 941 |
<div class="progress-bar-container">
|
| 942 |
+
<div id="{unique_id}" class="progress-bar-fill"></div>
|
| 943 |
</div>
|
| 944 |
<div class="est-time-text">Est. time: ~{est_time}s</div>
|
| 945 |
</div>
|
| 946 |
"""
|
| 947 |
else:
|
| 948 |
+
status_class, icon = "", str(idx + 1)
|
|
|
|
| 949 |
|
| 950 |
icons_html += f"""
|
| 951 |
<div class="step-item {status_class}">
|
|
|
|
| 957 |
icons_html += '<div class="step-arrow">➜</div>'
|
| 958 |
|
| 959 |
icons_html += '</div>'
|
|
|
|
| 960 |
text_html = f'<div class="step-status-text">{detail_msg}</div>'
|
|
|
|
|
|
|
| 961 |
return f'<div class="step-container">{icons_html}{active_progress_html}{text_html}</div>'
|
| 962 |
|
| 963 |
|
|
|
|
| 1949 |
.control-panel .gradio-dataframe { margin-top: 0 !important; margin-bottom: 0 !important; }
|
| 1950 |
.btn-row { display: flex; flex-direction: row; align-items: center; }
|
| 1951 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1952 |
.progress-bar-container {
|
| 1953 |
width: 100%;
|
| 1954 |
background-color: #f1f5f9;
|
| 1955 |
+
border-radius: 10px; /* 圆角稍微大一点更好看 */
|
| 1956 |
+
height: 8px;
|
| 1957 |
margin-top: 8px;
|
| 1958 |
overflow: hidden;
|
| 1959 |
+
border: 1px solid #e2e8f0;
|
| 1960 |
}
|
| 1961 |
|
| 1962 |
.progress-bar-fill {
|
| 1963 |
height: 100%;
|
| 1964 |
+
background: linear-gradient(90deg, #0ea5e9, #22c55e); /* 增加渐变效果 */
|
| 1965 |
width: 0%;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1966 |
}
|
| 1967 |
|
| 1968 |
.est-time-text {
|
| 1969 |
+
font-size: 0.7rem;
|
| 1970 |
+
color: #94a3b8;
|
| 1971 |
margin-top: 4px;
|
| 1972 |
+
text-align: center;
|
| 1973 |
+
font-family: 'JetBrains Mono', monospace;
|
| 1974 |
+
}
|
| 1975 |
+
|
| 1976 |
+
/* === 新增: 用户指南样式 (保持不变) === */
|
| 1977 |
+
.info-box {
|
| 1978 |
+
background: #f0f9ff;
|
| 1979 |
+
border: 1px solid #bae6fd;
|
| 1980 |
+
color: #0369a1;
|
| 1981 |
+
padding: 12px 16px;
|
| 1982 |
+
border-radius: 8px;
|
| 1983 |
+
font-size: 0.85rem;
|
| 1984 |
+
line-height: 1.5;
|
| 1985 |
+
margin-bottom: 16px;
|
| 1986 |
}
|
| 1987 |
|
| 1988 |
@keyframes progressFill {
|