shourya commited on
Commit
d1105a7
·
1 Parent(s): 96d64c3

Use explicit Spaces GPU decorators

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -11,14 +11,16 @@ import pandas as pd
11
  try:
12
  import spaces
13
  except Exception:
14
- spaces = None
 
 
 
 
 
 
 
15
 
16
-
17
- def _gpu_decorator(func):
18
- """Use Spaces GPU decorator when available; no-op locally."""
19
- if spaces is None:
20
- return func
21
- return spaces.GPU(func)
22
 
23
  # ===================== UTILITIES =====================
24
 
@@ -83,7 +85,7 @@ def get_embeddings_examples():
83
 
84
  # ===================== SENTIMENT ANALYSIS =====================
85
 
86
- @_gpu_decorator
87
  def demo_sentiment(text):
88
  """Demo sentiment analysis."""
89
  if not text.strip():
@@ -95,7 +97,7 @@ def demo_sentiment(text):
95
 
96
  # ===================== NER =====================
97
 
98
- @_gpu_decorator
99
  def demo_ner(text):
100
  """Demo named entity recognition."""
101
  if not text.strip():
@@ -109,7 +111,7 @@ def demo_ner(text):
109
 
110
  # ===================== QUESTION ANSWERING =====================
111
 
112
- @_gpu_decorator
113
  def demo_qa(context, question):
114
  """Demo question answering."""
115
  if not context.strip() or not question.strip():
@@ -123,7 +125,7 @@ def demo_qa(context, question):
123
 
124
  # ===================== SUMMARIZATION =====================
125
 
126
- @_gpu_decorator
127
  def demo_summarization(text):
128
  """Demo text summarization."""
129
  if not text.strip():
@@ -140,7 +142,7 @@ def demo_summarization(text):
140
 
141
  # ===================== SEMANTIC SIMILARITY =====================
142
 
143
- @_gpu_decorator
144
  def demo_similarity(text1, text2):
145
  """Demo semantic similarity."""
146
  if not text1.strip() or not text2.strip():
@@ -154,7 +156,7 @@ def demo_similarity(text1, text2):
154
 
155
  # ===================== TOKENIZATION =====================
156
 
157
- @_gpu_decorator
158
  def demo_tokenization(text):
159
  """Demo tokenization."""
160
  if not text.strip():
 
11
  try:
12
  import spaces
13
  except Exception:
14
+ class _SpacesFallback:
15
+ @staticmethod
16
+ def GPU(func=None, *args, **kwargs):
17
+ if func is None:
18
+ def decorator(inner_func):
19
+ return inner_func
20
+ return decorator
21
+ return func
22
 
23
+ spaces = _SpacesFallback()
 
 
 
 
 
24
 
25
  # ===================== UTILITIES =====================
26
 
 
85
 
86
  # ===================== SENTIMENT ANALYSIS =====================
87
 
88
+ @spaces.GPU
89
  def demo_sentiment(text):
90
  """Demo sentiment analysis."""
91
  if not text.strip():
 
97
 
98
  # ===================== NER =====================
99
 
100
+ @spaces.GPU
101
  def demo_ner(text):
102
  """Demo named entity recognition."""
103
  if not text.strip():
 
111
 
112
  # ===================== QUESTION ANSWERING =====================
113
 
114
+ @spaces.GPU
115
  def demo_qa(context, question):
116
  """Demo question answering."""
117
  if not context.strip() or not question.strip():
 
125
 
126
  # ===================== SUMMARIZATION =====================
127
 
128
+ @spaces.GPU
129
  def demo_summarization(text):
130
  """Demo text summarization."""
131
  if not text.strip():
 
142
 
143
  # ===================== SEMANTIC SIMILARITY =====================
144
 
145
+ @spaces.GPU
146
  def demo_similarity(text1, text2):
147
  """Demo semantic similarity."""
148
  if not text1.strip() or not text2.strip():
 
156
 
157
  # ===================== TOKENIZATION =====================
158
 
159
+ @spaces.GPU
160
  def demo_tokenization(text):
161
  """Demo tokenization."""
162
  if not text.strip():