Spaces:
Running
Running
new-human commited on
Commit ·
4f9d2b1
1
Parent(s): a7536a2
fix: 修复Python 3.14 asyncio循环错误并更新数据目录路径
Browse files修复在Python 3.14环境中Gradio可能遇到的asyncio事件循环运行时错误,通过显式检查并设置事件循环。同时将硬编码的绝对路径"/data/runs"改为相对路径"./data/runs",提高代码的可移植性。
app.py
CHANGED
|
@@ -1,6 +1,13 @@
|
|
| 1 |
import json
|
| 2 |
import threading
|
| 3 |
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
|
|
@@ -12,7 +19,7 @@ LOCK = threading.Lock()
|
|
| 12 |
|
| 13 |
|
| 14 |
def _runs_dir() -> Path:
|
| 15 |
-
d = Path("/data/runs")
|
| 16 |
d.mkdir(parents=True, exist_ok=True)
|
| 17 |
return d
|
| 18 |
|
|
|
|
| 1 |
import json
|
| 2 |
import threading
|
| 3 |
from pathlib import Path
|
| 4 |
+
import asyncio
|
| 5 |
+
|
| 6 |
+
# Fix Python 3.14 asyncio loop error in Gradio
|
| 7 |
+
try:
|
| 8 |
+
asyncio.get_event_loop()
|
| 9 |
+
except RuntimeError:
|
| 10 |
+
asyncio.set_event_loop(asyncio.new_event_loop())
|
| 11 |
|
| 12 |
import gradio as gr
|
| 13 |
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
def _runs_dir() -> Path:
|
| 22 |
+
d = Path("./data/runs")
|
| 23 |
d.mkdir(parents=True, exist_ok=True)
|
| 24 |
return d
|
| 25 |
|