myhloli commited on
Commit
53bc2ca
·
1 Parent(s): 638e42a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -14,22 +14,24 @@ os.system('pip install git+https://github.com/myhloli/Magic-PDF.git@dev')
14
 
15
  os.system('mineru-models-download -s huggingface -m all')
16
 
17
- with open('/home/user/mineru.json', 'r') as file:
 
18
  config = json.load(file)
19
-
20
- delimiters = {
21
- 'display': {'left': '\\[', 'right': '\\]'},
22
- 'inline': {'left': '\\(', 'right': '\\)'}
23
- }
24
-
25
- config['latex-delimiter-config'] = delimiters
26
-
27
- if os.getenv('apikey'):
28
- config['llm-aided-config']['title_aided']['api_key'] = os.getenv('apikey')
29
- config['llm-aided-config']['title_aided']['enable'] = True
30
-
31
- with open('/home/user/mineru.json', 'w') as file:
32
- json.dump(config, file, indent=4)
 
33
 
34
  from gradio_pdf import PDF
35
  import gradio as gr
 
14
 
15
  os.system('mineru-models-download -s huggingface -m all')
16
 
17
+ try:
18
+ with open('/home/user/mineru.json', 'r+') as file:
19
  config = json.load(file)
20
+
21
+ delimiters = {
22
+ 'display': {'left': '\\[', 'right': '\\]'},
23
+ 'inline': {'left': '\\(', 'right': '\\)'}
24
+ }
25
+
26
+ config['latex-delimiter-config'] = delimiters
27
+
28
+ if os.getenv('apikey'):
29
+ config['llm-aided-config']['title_aided']['api_key'] = os.getenv('apikey')
30
+ config['llm-aided-config']['title_aided']['enable'] = True
31
+
32
+ file.seek(0) # 将文件指针移回文件开始位置
33
+ file.truncate() # 截断文件,清除原有内容
34
+ json.dump(config, file, indent=4) # 写入新内容
35
 
36
  from gradio_pdf import PDF
37
  import gradio as gr