|
8 | 8 |
|
9 | 9 | import huggingface_hub
|
10 | 10 | import requests
|
| 11 | +from huggingface_hub import HfApi |
| 12 | +from huggingface_hub.utils import LocalTokenNotFoundError |
11 | 13 | from tornado.web import HTTPError
|
12 | 14 |
|
13 | 15 | from ads.aqua import ODSC_MODEL_COMPARTMENT_OCID
|
14 | 16 | from ads.aqua.common.decorator import handle_exceptions
|
15 |
| -from ads.aqua.common.errors import AquaResourceAccessError |
| 17 | +from ads.aqua.common.errors import AquaResourceAccessError, AquaRuntimeError |
16 | 18 | from ads.aqua.common.utils import fetch_service_compartment, known_realm
|
17 | 19 | from ads.aqua.extension.base_handler import AquaAPIhandler
|
18 | 20 | from ads.aqua.extension.errors import Errors
|
@@ -96,9 +98,26 @@ def post(self, *args, **kwargs):
|
96 | 98 | return self.finish("success")
|
97 | 99 |
|
98 | 100 |
|
| 101 | +class HFUserStatusHandler(AquaAPIhandler): |
| 102 | + """Handler to check if user logged in to the HF.""" |
| 103 | + |
| 104 | + @handle_exceptions |
| 105 | + def get(self): |
| 106 | + try: |
| 107 | + HfApi().whoami() |
| 108 | + except LocalTokenNotFoundError: |
| 109 | + raise AquaRuntimeError( |
| 110 | + "You are not logged in. Please log in to Hugging Face using the `huggingface-cli login` command." |
| 111 | + "See https://huggingface.co/settings/tokens.", |
| 112 | + ) |
| 113 | + |
| 114 | + return self.finish("success") |
| 115 | + |
| 116 | + |
99 | 117 | __handlers__ = [
|
100 | 118 | ("ads_version", ADSVersionHandler),
|
101 | 119 | ("hello", CompatibilityCheckHandler),
|
102 | 120 | ("network_status", NetworkStatusHandler),
|
103 | 121 | ("hf_login", HFLoginHandler),
|
| 122 | + ("hf_logged_in", HFUserStatusHandler), |
104 | 123 | ]
|
0 commit comments