Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,11 +18,34 @@ outputs.append(gr.JSON())
|
|
| 18 |
|
| 19 |
expected_outputs = len(outputs)
|
| 20 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
headers = {'Content-Type': 'application/json'}
|
| 22 |
|
| 23 |
payload = {"input": {}}
|
| 24 |
|
| 25 |
-
|
| 26 |
base_url = "http://0.0.0.0:7860"
|
| 27 |
for i, key in enumerate(names):
|
| 28 |
value = args[i]
|
|
|
|
| 18 |
|
| 19 |
expected_outputs = len(outputs)
|
| 20 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
| 21 |
+
|
| 22 |
+
# TODO: extract the Bearer access token from the request
|
| 23 |
+
if not request:
|
| 24 |
+
raise gr.Error("The submission failed!")
|
| 25 |
+
|
| 26 |
+
print("Request headers dictionary:", request.headers)
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
authorization = request.headers["Authorization"]
|
| 30 |
+
except KeyError:
|
| 31 |
+
raise gr.Error("Missing authorization in the headers")
|
| 32 |
+
|
| 33 |
+
# Extract the token part from the authorization
|
| 34 |
+
try:
|
| 35 |
+
bearer, token = authorization.split(" ")
|
| 36 |
+
except ValueError:
|
| 37 |
+
raise gr.Error("Invalid format for Authorization header. It should be 'Bearer <token>'")
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
hf_api = HfApi(token=token)
|
| 41 |
+
userInfo = hf_api.whoami(token)
|
| 42 |
+
if not userInfo:
|
| 43 |
+
raise gr.Error("The provided API key is invalid!")
|
| 44 |
+
|
| 45 |
headers = {'Content-Type': 'application/json'}
|
| 46 |
|
| 47 |
payload = {"input": {}}
|
| 48 |
|
|
|
|
| 49 |
base_url = "http://0.0.0.0:7860"
|
| 50 |
for i, key in enumerate(names):
|
| 51 |
value = args[i]
|