Spaces:
Running
on
Zero
Running
on
Zero
Update models.py
Browse files
models.py
CHANGED
|
@@ -45,21 +45,40 @@ class BagelAPIAnalyzer(BaseImageAnalyzer):
|
|
| 45 |
self.client = None
|
| 46 |
self.space_url = "Malaji71/Bagel-7B-Demo"
|
| 47 |
self.api_endpoint = "/image_understanding"
|
|
|
|
| 48 |
|
| 49 |
def initialize(self) -> bool:
|
| 50 |
-
"""Initialize BAGEL API client"""
|
| 51 |
if self.is_initialized:
|
| 52 |
return True
|
| 53 |
|
| 54 |
try:
|
| 55 |
logger.info("Initializing BAGEL API client...")
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
self.is_initialized = True
|
| 58 |
logger.info("BAGEL API client initialized successfully")
|
| 59 |
return True
|
| 60 |
|
| 61 |
except Exception as e:
|
| 62 |
logger.error(f"BAGEL API client initialization failed: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
return False
|
| 64 |
|
| 65 |
def _extract_camera_setup(self, description: str) -> Optional[str]:
|
|
|
|
| 45 |
self.client = None
|
| 46 |
self.space_url = "Malaji71/Bagel-7B-Demo"
|
| 47 |
self.api_endpoint = "/image_understanding"
|
| 48 |
+
self.hf_token = os.getenv("HF_TOKEN") # Get token from environment/secrets
|
| 49 |
|
| 50 |
def initialize(self) -> bool:
|
| 51 |
+
"""Initialize BAGEL API client with authentication"""
|
| 52 |
if self.is_initialized:
|
| 53 |
return True
|
| 54 |
|
| 55 |
try:
|
| 56 |
logger.info("Initializing BAGEL API client...")
|
| 57 |
+
|
| 58 |
+
# Initialize client with token if available (for private spaces)
|
| 59 |
+
if self.hf_token:
|
| 60 |
+
logger.info("Using HF token for private space access")
|
| 61 |
+
self.client = Client(self.space_url, hf_token=self.hf_token)
|
| 62 |
+
else:
|
| 63 |
+
logger.info("No HF token found, accessing public space")
|
| 64 |
+
self.client = Client(self.space_url)
|
| 65 |
+
|
| 66 |
self.is_initialized = True
|
| 67 |
logger.info("BAGEL API client initialized successfully")
|
| 68 |
return True
|
| 69 |
|
| 70 |
except Exception as e:
|
| 71 |
logger.error(f"BAGEL API client initialization failed: {e}")
|
| 72 |
+
# If private space fails, try without token as fallback
|
| 73 |
+
if self.hf_token:
|
| 74 |
+
logger.info("Retrying without token...")
|
| 75 |
+
try:
|
| 76 |
+
self.client = Client(self.space_url)
|
| 77 |
+
self.is_initialized = True
|
| 78 |
+
logger.info("BAGEL API client initialized successfully (fallback to public)")
|
| 79 |
+
return True
|
| 80 |
+
except Exception as e2:
|
| 81 |
+
logger.error(f"Fallback initialization also failed: {e2}")
|
| 82 |
return False
|
| 83 |
|
| 84 |
def _extract_camera_setup(self, description: str) -> Optional[str]:
|