uatjonas commited on
Commit
1711781
·
verified ·
1 Parent(s): f12a6ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -12,11 +12,9 @@ MODEL_DIR = os.path.join(HOME, "models")
12
  print("--- Starting MinerU Setup ---")
13
 
14
  # 2. Download Models (if not present)
15
- # Note: This might take a few minutes on the first start!
16
  if not os.path.exists(MODEL_DIR):
17
  print(f"Downloading models to {MODEL_DIR}...")
18
  try:
19
- # Download core models
20
  snapshot_download(
21
  "opendatalab/PDF-Extract-Kit-1.0",
22
  local_dir=MODEL_DIR,
@@ -30,13 +28,15 @@ else:
30
  print("Models found. Skipping download.")
31
 
32
  # 3. Generate magic-pdf.json Config
33
- # MinerU requires this file to know where the models are.
 
 
34
  config_data = {
35
- "models-dir": REAL_MODEL_DIR,
36
- "device-mode": "cpu", # Change to "cuda" if you are using a GPU Space
37
  "table-config": {
38
  "model": "TableMaster",
39
- "is_table_recog_enable": False, # Disable table recognition for speed on CPU
40
  "max_time": 400
41
  }
42
  }
@@ -48,11 +48,10 @@ with open(CONFIG_FILE, "w") as f:
48
  # 4. Launch the MinerU REST API
49
  print("Launching MinerU REST API...")
50
 
51
- # Change the command to use mineru-api instead of mineru-gradio
52
  command = [
53
  "mineru-api",
54
  "--host", "0.0.0.0",
55
- "--port", "7860" # HF Spaces requires port 7860
56
  ]
57
 
58
  subprocess.run(command)
 
12
  print("--- Starting MinerU Setup ---")
13
 
14
  # 2. Download Models (if not present)
 
15
  if not os.path.exists(MODEL_DIR):
16
  print(f"Downloading models to {MODEL_DIR}...")
17
  try:
 
18
  snapshot_download(
19
  "opendatalab/PDF-Extract-Kit-1.0",
20
  local_dir=MODEL_DIR,
 
28
  print("Models found. Skipping download.")
29
 
30
  # 3. Generate magic-pdf.json Config
31
+ # FIX: Define REAL_MODEL_DIR before using it
32
+ REAL_MODEL_DIR = os.path.join(MODEL_DIR, "models")
33
+
34
  config_data = {
35
+ "models-dir": REAL_MODEL_DIR, # Now this variable exists
36
+ "device-mode": "cpu",
37
  "table-config": {
38
  "model": "TableMaster",
39
+ "is_table_recog_enable": False,
40
  "max_time": 400
41
  }
42
  }
 
48
  # 4. Launch the MinerU REST API
49
  print("Launching MinerU REST API...")
50
 
 
51
  command = [
52
  "mineru-api",
53
  "--host", "0.0.0.0",
54
+ "--port", "7860"
55
  ]
56
 
57
  subprocess.run(command)