Spaces:
Sleeping
Sleeping
import os | |
import sys | |
from pathlib import Path | |
import gradio as gr | |
# 添加当前目录和src目录到模块搜索路径 | |
current_dir = os.path.dirname(os.path.abspath(__file__)) | |
src_dir = os.path.join(current_dir, "src") | |
if current_dir not in sys.path: | |
sys.path.append(current_dir) | |
if src_dir not in sys.path: | |
sys.path.append(src_dir) | |
from src.queue_manager import QueueManager | |
from src.evaluator import evaluate | |
from src.ui import EvaluationUI | |
def main(): | |
"""主函数,创建并启动应用""" | |
# 创建队列管理器 | |
queue_manager = QueueManager() | |
# 设置评估函数 | |
queue_manager.set_evaluator(evaluate) | |
# 创建UI | |
ui = EvaluationUI(queue_manager) | |
app = ui.create_evaluation_interface() | |
# 启动清理线程 | |
import threading | |
import time | |
def cleanup_thread(): | |
"""定期清理已完成的请求""" | |
while True: | |
try: | |
queue_manager.clean_completed(max_age=3600) # 清理1小时前的已完成请求 | |
except Exception as e: | |
print(f"Error in cleanup thread: {e}") | |
time.sleep(600) # 每10分钟运行一次 | |
cleanup_thread = threading.Thread(target=cleanup_thread, daemon=True) | |
cleanup_thread.start() | |
# 返回应用 | |
return app | |
if __name__ == "__main__": | |
app = main() | |
app.launch() |