Spaces:
Sleeping
Sleeping
朱东升
commited on
Commit
·
1bac4cd
1
Parent(s):
7f83e08
update8
Browse files
app.py
CHANGED
@@ -141,19 +141,6 @@ def process_task_queue():
|
|
141 |
|
142 |
except Exception as e:
|
143 |
print(f"Error processing task queue: {str(e)}")
|
144 |
-
# 出错时也触发UI更新
|
145 |
-
with task_lock:
|
146 |
-
if task_id in active_tasks:
|
147 |
-
active_tasks[task_id]["status"] = "error"
|
148 |
-
active_tasks[task_id]["error"] = str(e)
|
149 |
-
active_tasks[task_id]["completed_at"] = datetime.now()
|
150 |
-
# 将任务移至已完成列表
|
151 |
-
completed_tasks.append(active_tasks[task_id])
|
152 |
-
del active_tasks[task_id]
|
153 |
-
# 保留最近的20个已完成任务
|
154 |
-
if len(completed_tasks) > 20:
|
155 |
-
completed_tasks.pop(0)
|
156 |
-
trigger_ui_update()
|
157 |
time.sleep(1)
|
158 |
|
159 |
def evaluate(input_data):
|
@@ -440,10 +427,11 @@ with gr.Blocks(title="代码评估服务", theme=gr.themes.Soft()) as demo:
|
|
440 |
refresh_button = gr.Button("刷新状态")
|
441 |
refresh_button.click(fn=refresh_ui, outputs=status_html)
|
442 |
|
443 |
-
#
|
444 |
-
|
|
|
445 |
|
446 |
-
# JavaScript
|
447 |
gr.HTML("""
|
448 |
<script>
|
449 |
// 使用JavaScript作为备份的自动刷新
|
@@ -463,8 +451,11 @@ with gr.Blocks(title="代码评估服务", theme=gr.themes.Soft()) as demo:
|
|
463 |
}
|
464 |
}
|
465 |
|
466 |
-
//
|
467 |
setInterval(autoRefresh, refreshInterval);
|
|
|
|
|
|
|
468 |
}
|
469 |
|
470 |
// 页面加载完成后设置自动刷新
|
@@ -548,5 +539,12 @@ with gr.Blocks(title="代码评估服务", theme=gr.themes.Soft()) as demo:
|
|
548 |
api_input.change(fn=evaluate, inputs=api_input, outputs=api_output)
|
549 |
|
550 |
if __name__ == "__main__":
|
551 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
552 |
demo.launch()
|
|
|
141 |
|
142 |
except Exception as e:
|
143 |
print(f"Error processing task queue: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
time.sleep(1)
|
145 |
|
146 |
def evaluate(input_data):
|
|
|
427 |
refresh_button = gr.Button("刷新状态")
|
428 |
refresh_button.click(fn=refresh_ui, outputs=status_html)
|
429 |
|
430 |
+
# 使用正确的轮询方式替代
|
431 |
+
dummy_input = gr.Textbox(value="", visible=False)
|
432 |
+
dummy_input.change(fn=check_for_updates, inputs=dummy_input, outputs=status_html, every=1)
|
433 |
|
434 |
+
# JavaScript刷新作为备份
|
435 |
gr.HTML("""
|
436 |
<script>
|
437 |
// 使用JavaScript作为备份的自动刷新
|
|
|
451 |
}
|
452 |
}
|
453 |
|
454 |
+
// 周期性检查刷新
|
455 |
setInterval(autoRefresh, refreshInterval);
|
456 |
+
|
457 |
+
// 设置首次加载时立即刷新一次
|
458 |
+
setTimeout(autoRefresh, 100);
|
459 |
}
|
460 |
|
461 |
// 页面加载完成后设置自动刷新
|
|
|
539 |
api_input.change(fn=evaluate, inputs=api_input, outputs=api_output)
|
540 |
|
541 |
if __name__ == "__main__":
|
542 |
+
# 打印Gradio版本,用于调试
|
543 |
+
import gradio
|
544 |
+
print(f"Gradio version: {gradio.__version__}")
|
545 |
+
|
546 |
+
# 设置队列,并添加API支持
|
547 |
+
demo.queue(api_open=True)
|
548 |
+
|
549 |
+
# 启动应用
|
550 |
demo.launch()
|