Felix92 commited on
Commit
a384f99
·
verified ·
1 Parent(s): 332b9fc

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +16 -0
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,6 +1,21 @@
1
  import io
 
2
  from typing import Any, List, Union
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import cv2
5
  import gradio as gr
6
  import matplotlib.pyplot as plt
@@ -139,6 +154,7 @@ def matplotlib_to_pil(fig: Union[Figure, np.ndarray]) -> Image.Image:
139
  return Image.open(buf)
140
 
141
 
 
142
  def analyze_page(
143
  uploaded_file: Any,
144
  page_idx: int,
 
1
  import io
2
+ import os
3
  from typing import Any, List, Union
4
 
5
+ # NOTE: This is a fix to run the demo on the HuggingFace Zero GPU or CPU spaces
6
+ if os.environ.get("SPACES_ZERO_GPU") is not None:
7
+ import spaces
8
+ else:
9
+
10
+ class spaces: # noqa: N801
11
+ @staticmethod
12
+ def GPU(func): # noqa: N802
13
+ def wrapper(*args, **kwargs):
14
+ return func(*args, **kwargs)
15
+
16
+ return wrapper
17
+
18
+
19
  import cv2
20
  import gradio as gr
21
  import matplotlib.pyplot as plt
 
154
  return Image.open(buf)
155
 
156
 
157
+ @spaces.GPU
158
  def analyze_page(
159
  uploaded_file: Any,
160
  page_idx: int,
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  -e git+https://github.com/felixdittrich92/OnnxTR.git#egg=onnxtr[gpu-headless,viz]
2
  gradio>=4.37.1,<6.0.0
 
 
1
  -e git+https://github.com/felixdittrich92/OnnxTR.git#egg=onnxtr[gpu-headless,viz]
2
  gradio>=4.37.1,<6.0.0
3
+ spaces>=0.30.4