Srishti280992 commited on
Commit
c1b0f6d
·
verified ·
1 Parent(s): 12e0cfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -150,7 +150,25 @@ class OptionalHFInferenceClient:
150
  from huggingface_hub import InferenceClient
151
 
152
  self.model_id = model_id.strip().strip('"').strip("'").strip()
153
- self.client = InferenceClient(model=self.model_id, token=token)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  def generate(
156
  self,
@@ -351,8 +369,12 @@ def build_optional_model_client() -> tuple[Any | None, AppModelStatus]:
351
  os.getenv("WORLDSMITHAI_MODEL_ID")
352
  or os.getenv("WORLD_SMITH_MODEL_ID")
353
  or os.getenv("HF_MODEL_ID")
354
- )
355
- token = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN")
 
 
 
 
356
 
357
  if not raw_model_id:
358
  return None, AppModelStatus(
 
150
  from huggingface_hub import InferenceClient
151
 
152
  self.model_id = model_id.strip().strip('"').strip("'").strip()
153
+
154
+ api_key = (
155
+ token
156
+ or os.getenv("HF_TOKEN")
157
+ or os.getenv("HF_HUB_TOKEN")
158
+ or os.getenv("HUGGINGFACEHUB_API_TOKEN")
159
+ )
160
+
161
+ if not api_key:
162
+ raise RuntimeError(
163
+ "HF_TOKEN is required for Hugging Face Inference Providers. "
164
+ "Create a Hugging Face token with Inference Providers permission "
165
+ "and add it as a Space secret named HF_TOKEN."
166
+ )
167
+
168
+ self.client = InferenceClient(
169
+ model=self.model_id,
170
+ api_key=api_key,
171
+ )
172
 
173
  def generate(
174
  self,
 
369
  os.getenv("WORLDSMITHAI_MODEL_ID")
370
  or os.getenv("WORLD_SMITH_MODEL_ID")
371
  or os.getenv("HF_MODEL_ID")
372
+ )
373
+ token = (
374
+ os.getenv("HF_TOKEN")
375
+ or os.getenv("HF_HUB_TOKEN")
376
+ or os.getenv("HUGGINGFACEHUB_API_TOKEN")
377
+ )
378
 
379
  if not raw_model_id:
380
  return None, AppModelStatus(