Skip to content

Commit c4d475c

Browse files
feat(webui): temp storage for user data
1 parent 7831d09 commit c4d475c

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

webui/app.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from gradio_i18n import Translate, gettext as _
99
from test_api import test_api_connection
10+
from cache_utils import setup_workspace, cleanup_workspace
1011

1112
# pylint: disable=wrong-import-position
1213
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -25,7 +26,12 @@
2526

2627

2728
def init_graph_gen(config: dict, env: dict) -> GraphGen:
28-
graph_gen = GraphGen()
29+
# Set up working directory
30+
working_dir = setup_workspace(os.path.join(root_dir, "cache"))
31+
32+
graph_gen = GraphGen(
33+
working_dir=working_dir
34+
)
2935

3036
# Set up LLM clients
3137
graph_gen.synthesizer_llm_client = OpenAIModel(
@@ -160,12 +166,14 @@ def run_graphgen(*arguments: list, progress=gr.Progress()):
160166
with tempfile.NamedTemporaryFile(
161167
mode="w",
162168
suffix=".jsonl",
163-
delete=False, # 防止自动删除
169+
delete=False,
164170
encoding="utf-8") as tmpfile:
165-
# 假设qa_storage有导出数据的方法
166171
json.dump(output_data, tmpfile, ensure_ascii=False)
167172
output_file = tmpfile.name
168173

174+
# Clean up workspace
175+
cleanup_workspace(graph_gen.working_dir)
176+
169177
progress(1.0, "Graph traversed")
170178
return output_file
171179

webui/cache_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
import uuid
3+
import shutil
4+
5+
def setup_workspace(folder):
6+
request_id = str(uuid.uuid4())
7+
os.makedirs(folder, exist_ok=True)
8+
9+
working_dir = os.path.join(folder, request_id)
10+
os.makedirs(working_dir, exist_ok=True)
11+
12+
return working_dir
13+
14+
15+
def cleanup_workspace(folder):
16+
if os.path.exists(folder):
17+
shutil.rmtree(folder)
18+
return True

0 commit comments

Comments
 (0)