File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 77
88from gradio_i18n import Translate , gettext as _
99from test_api import test_api_connection
10+ from cache_utils import setup_workspace , cleanup_workspace
1011
1112# pylint: disable=wrong-import-position
1213root_dir = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
2526
2627
2728def 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments