rjarun20 commited on
Commit
fe46b35
Β·
verified Β·
1 Parent(s): 56526e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -54,23 +54,29 @@ def get_client():
54
  # Try multiple token sources for Spaces
55
  api_token = None
56
 
57
- # Method 1: Spaces secrets (recommended)
58
  api_token = os.getenv("HF_API_TOKEN")
 
 
59
 
60
- # Method 2: Traditional environment variable
61
  if not api_token:
62
- api_token = os.getenv("HF_API_TOKEN")
 
 
63
 
64
  # Method 3: Hugging Face CLI token (if logged in)
65
  if not api_token:
66
  try:
67
  from huggingface_hub import get_token
68
  api_token = get_token()
 
 
69
  except:
70
  pass
71
 
72
  if not api_token:
73
- logger.warning("⚠️ No HF token found. Some features may be limited.")
74
  return None
75
 
76
  try:
@@ -98,7 +104,7 @@ CLIENT = get_client()
98
  def safe_call(func_name: str, func, *args, **kwargs):
99
  """Spaces-optimized safe API calls."""
100
  if not CLIENT:
101
- return "❌ API client not available. Please check if HF_TOKEN is set in Spaces secrets."
102
 
103
  try:
104
  logger.info(f"πŸ”„ {func_name}...")
@@ -449,7 +455,7 @@ with gr.Blocks(title="πŸš€ AI Research Hub", theme=gr.themes.Soft(), css=custom_
449
  else:
450
  gr.HTML("""
451
  <div class="status-indicator status-error">
452
- ❌ <strong>Status:</strong> Please set HF_TOKEN in Spaces settings
453
  </div>
454
  """)
455
 
@@ -613,7 +619,7 @@ with gr.Blocks(title="πŸš€ AI Research Hub", theme=gr.themes.Soft(), css=custom_
613
 
614
  **To use this Space:**
615
  1. Go to **Settings** β†’ **Repository secrets**
616
- 2. Add **HF_TOKEN** with your Hugging Face token
617
  3. Get your token at: [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
618
 
619
  **Features:**
 
54
  # Try multiple token sources for Spaces
55
  api_token = None
56
 
57
+ # Method 1: Check HF_API_TOKEN (your current setup)
58
  api_token = os.getenv("HF_API_TOKEN")
59
+ if api_token:
60
+ logger.info("βœ… Found HF_API_TOKEN")
61
 
62
+ # Method 2: Fallback to HF_TOKEN
63
  if not api_token:
64
+ api_token = os.getenv("HF_TOKEN")
65
+ if api_token:
66
+ logger.info("βœ… Found HF_TOKEN")
67
 
68
  # Method 3: Hugging Face CLI token (if logged in)
69
  if not api_token:
70
  try:
71
  from huggingface_hub import get_token
72
  api_token = get_token()
73
+ if api_token:
74
+ logger.info("βœ… Found CLI token")
75
  except:
76
  pass
77
 
78
  if not api_token:
79
+ logger.warning("⚠️ No HF token found. Please set HF_API_TOKEN or HF_TOKEN in Spaces secrets.")
80
  return None
81
 
82
  try:
 
104
  def safe_call(func_name: str, func, *args, **kwargs):
105
  """Spaces-optimized safe API calls."""
106
  if not CLIENT:
107
+ return "❌ API client not available. Please check if HF_API_TOKEN or HF_TOKEN is set in Spaces secrets."
108
 
109
  try:
110
  logger.info(f"πŸ”„ {func_name}...")
 
455
  else:
456
  gr.HTML("""
457
  <div class="status-indicator status-error">
458
+ ❌ <strong>Status:</strong> Please set HF_API_TOKEN or HF_TOKEN in Spaces settings
459
  </div>
460
  """)
461
 
 
619
 
620
  **To use this Space:**
621
  1. Go to **Settings** β†’ **Repository secrets**
622
+ 2. Add **HF_API_TOKEN** (or **HF_TOKEN**) with your Hugging Face token
623
  3. Get your token at: [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
624
 
625
  **Features:**