Views
No views yet
philschmi/gradio-api:cpuphilschmi/gradio-api:gpu7860/server_name="0.0.0.0" in your launch() call to make sure the request is correct proxied.public and add auth through gradio!wget https://datasets-server.huggingface.co/assets/naver-clova-ix/cord-v2/--/naver-clova-ix--cord-v2/train/0/image/image.jpg1import requests as r
2import base64
3
4ENDPOINT_URL = ""
5HF_TOKEN = ""
6
7def predict(path_to_image: str = None):
8 ext = path_to_image.split('.')[-1]
9 prefix = f'data:image/{ext};base64,'
10 with open(path_to_image, 'rb') as f:
11 img = f.read()
12
13 payload = {"data": [prefix + base64.b64encode(img).decode('utf-8')]}
14 response = r.post(
15 f"{ENDPOINT_URL}/api/predict", headers={"Authorization": f"Bearer {HF_TOKEN}"}, json=payload
16 )
17 if response.status_code == 200:
18 return response.json()
19 else:
20 raise Exception(f"Error: {response.status_code}")
21
22
23prediction = predict(path_to_image="image.jpg")
24