Akash212 commited on
Commit
d8d0f29
·
verified ·
1 Parent(s): d7b7e82

Run the model on CPU in the main process (no GPU request)

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -1,7 +1,6 @@
1
  """
2
  Gradio test UI for the SciHigh 2026 extractive highlight generator.
3
- Runs on CPU. On ZeroGPU hardware the handlers are wrapped with @spaces.GPU (required by ZeroGPU),
4
- but the model itself still runs on CPU.
5
  """
6
  import os, tempfile
7
  import numpy as np, pandas as pd
@@ -9,10 +8,15 @@ import gradio as gr
9
  from scihigh_model import SciHighExtractor, clean
10
 
11
  try:
 
 
12
  import spaces
13
- GPU_SHORT, GPU_LONG = spaces.GPU(duration=30), spaces.GPU(duration=120)
 
 
 
14
  except Exception:
15
- GPU_SHORT = GPU_LONG = (lambda f: f)
16
 
17
  HERE = os.path.dirname(os.path.abspath(__file__))
18
  MODEL = SciHighExtractor.from_pretrained(HERE, encoder=os.environ.get("SCIHIGH_ENCODER")) # optional local encoder path
@@ -58,7 +62,6 @@ def bullets(text):
58
  return "\n".join(f"- {p}." for p in parts)
59
 
60
 
61
- @GPU_SHORT
62
  def run_single(abstract, budget, maxs, mmr):
63
  if not abstract or len(abstract.split()) < 10:
64
  raise gr.Error("Please paste an abstract of at least a few sentences.")
@@ -69,7 +72,6 @@ def run_single(abstract, budget, maxs, mmr):
69
  return bullets(text), text, info, table
70
 
71
 
72
- @GPU_LONG
73
  def run_batch(file, budget, maxs, mmr):
74
  if file is None:
75
  raise gr.Error("Upload a CSV file first.")
 
1
  """
2
  Gradio test UI for the SciHigh 2026 extractive highlight generator.
3
+ The model runs entirely on CPU in the main process, so no GPU is ever requested.
 
4
  """
5
  import os, tempfile
6
  import numpy as np, pandas as pd
 
8
  from scihigh_model import SciHighExtractor, clean
9
 
10
  try:
11
+ # ZeroGPU hardware refuses to start unless one @spaces.GPU function exists. This placeholder satisfies
12
+ # that check; it is never called. On CPU hardware the `spaces` package is absent and this is skipped.
13
  import spaces
14
+
15
+ @spaces.GPU(duration=10)
16
+ def _zerogpu_placeholder():
17
+ return None
18
  except Exception:
19
+ pass
20
 
21
  HERE = os.path.dirname(os.path.abspath(__file__))
22
  MODEL = SciHighExtractor.from_pretrained(HERE, encoder=os.environ.get("SCIHIGH_ENCODER")) # optional local encoder path
 
62
  return "\n".join(f"- {p}." for p in parts)
63
 
64
 
 
65
  def run_single(abstract, budget, maxs, mmr):
66
  if not abstract or len(abstract.split()) < 10:
67
  raise gr.Error("Please paste an abstract of at least a few sentences.")
 
72
  return bullets(text), text, info, table
73
 
74
 
 
75
  def run_batch(file, budget, maxs, mmr):
76
  if file is None:
77
  raise gr.Error("Upload a CSV file first.")