xiaoyao9184 commited on
Commit
919648a
·
verified ·
1 Parent(s): faba643

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (1) hide show
  1. gradio_app.py +11 -10
gradio_app.py CHANGED
@@ -2,11 +2,12 @@ import os
2
  import sys
3
 
4
  if "APP_PATH" in os.environ:
5
- os.chdir(os.environ["APP_PATH"])
6
- # fix sys.path for import
7
- sys.path.append(os.getcwd())
8
-
9
- print(os.getenv("XDG_CACHE_HOME"))
 
10
 
11
  import gradio as gr
12
 
@@ -20,8 +21,6 @@ os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
20
  os.environ["IN_STREAMLIT"] = "true"
21
  import pypdfium2
22
 
23
- import io
24
- import tempfile
25
  from PIL import Image
26
 
27
  from tabled.inference.models import load_detection_models, load_recognition_models, load_layout_models
@@ -70,8 +69,9 @@ def get_page_image(pdf_file, page_num, dpi=96):
70
  def get_uploaded_image(in_file):
71
  return Image.open(in_file).convert("RGB")
72
 
73
-
74
- models = load_models()
 
75
 
76
  with gr.Blocks(title="Tabled") as demo:
77
  gr.Markdown("""
@@ -142,4 +142,5 @@ with gr.Blocks(title="Tabled") as demo:
142
  outputs=[result_img, result_md]
143
  )
144
 
145
- demo.launch()
 
 
2
  import sys
3
 
4
  if "APP_PATH" in os.environ:
5
+ app_path = os.path.abspath(os.environ["APP_PATH"])
6
+ if os.getcwd() != app_path:
7
+ # fix sys.path for import
8
+ os.chdir(app_path)
9
+ if app_path not in sys.path:
10
+ sys.path.append(app_path)
11
 
12
  import gradio as gr
13
 
 
21
  os.environ["IN_STREAMLIT"] = "true"
22
  import pypdfium2
23
 
 
 
24
  from PIL import Image
25
 
26
  from tabled.inference.models import load_detection_models, load_recognition_models, load_layout_models
 
69
  def get_uploaded_image(in_file):
70
  return Image.open(in_file).convert("RGB")
71
 
72
+ # Load models if not already loaded in reload mode
73
+ if 'models' not in globals():
74
+ models = load_models()
75
 
76
  with gr.Blocks(title="Tabled") as demo:
77
  gr.Markdown("""
 
142
  outputs=[result_img, result_md]
143
  )
144
 
145
+ if __name__ == "__main__":
146
+ demo.launch()