Ansemin101 commited on
Commit
36e49b4
·
1 Parent(s): 4fab3b3

runtime error fix

Browse files
Files changed (2) hide show
  1. app.py +8 -8
  2. src/parsers/got_ocr_parser.py +7 -7
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import sys
2
  import os
3
  import subprocess
@@ -23,6 +24,13 @@ try:
23
  except Exception as e:
24
  print(f"Error running setup.sh: {e}")
25
 
 
 
 
 
 
 
 
26
  # Check for PyTorch and CUDA availability (needed for GOT-OCR)
27
  try:
28
  import torch
@@ -56,14 +64,6 @@ except ImportError:
56
  print("WARNING: NumPy not installed. Installing NumPy 1.26.3...")
57
  subprocess.run([sys.executable, "-m", "pip", "install", "-q", "numpy==1.26.3"], check=False)
58
 
59
- # Check if spaces module is installed (needed for ZeroGPU)
60
- try:
61
- import spaces
62
- print("Spaces module found for ZeroGPU support")
63
- except ImportError:
64
- print("WARNING: Spaces module not found. Installing...")
65
- subprocess.run([sys.executable, "-m", "pip", "install", "-q", "spaces"], check=False)
66
-
67
  # Try to load environment variables from .env file
68
  try:
69
  from dotenv import load_dotenv
 
1
+ import spaces # Must be imported before any CUDA initialization
2
  import sys
3
  import os
4
  import subprocess
 
24
  except Exception as e:
25
  print(f"Error running setup.sh: {e}")
26
 
27
+ # Check if spaces module is installed (needed for ZeroGPU)
28
+ try:
29
+ print("Spaces module found for ZeroGPU support")
30
+ except ImportError:
31
+ print("WARNING: Spaces module not found. Installing...")
32
+ subprocess.run([sys.executable, "-m", "pip", "install", "-q", "spaces"], check=False)
33
+
34
  # Check for PyTorch and CUDA availability (needed for GOT-OCR)
35
  try:
36
  import torch
 
64
  print("WARNING: NumPy not installed. Installing NumPy 1.26.3...")
65
  subprocess.run([sys.executable, "-m", "pip", "install", "-q", "numpy==1.26.3"], check=False)
66
 
 
 
 
 
 
 
 
 
67
  # Try to load environment variables from .env file
68
  try:
69
  from dotenv import load_dotenv
src/parsers/got_ocr_parser.py CHANGED
@@ -1,3 +1,10 @@
 
 
 
 
 
 
 
1
  from pathlib import Path
2
  import os
3
  import logging
@@ -6,13 +13,6 @@ import tempfile
6
  import shutil
7
  from typing import Dict, List, Optional, Any, Union
8
 
9
- # Import spaces module for ZeroGPU support
10
- try:
11
- import spaces
12
- HAS_SPACES = True
13
- except ImportError:
14
- HAS_SPACES = False
15
-
16
  from src.parsers.parser_interface import DocumentParser
17
  from src.parsers.parser_registry import ParserRegistry
18
 
 
1
+ # Import spaces module for ZeroGPU support - Must be first import
2
+ try:
3
+ import spaces
4
+ HAS_SPACES = True
5
+ except ImportError:
6
+ HAS_SPACES = False
7
+
8
  from pathlib import Path
9
  import os
10
  import logging
 
13
  import shutil
14
  from typing import Dict, List, Optional, Any, Union
15
 
 
 
 
 
 
 
 
16
  from src.parsers.parser_interface import DocumentParser
17
  from src.parsers.parser_registry import ParserRegistry
18