File size: 713 Bytes
bf45da8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import os
import requests

STAMP_DETECTION_API = "https://point9-signature-and-stamp-detection.hf.space/api/stamp-detection"  # Replace with your space URL

def stamp_detection_remote(state):
    filename = state["filename"]
    path = state["temp_files"][filename]

    with open(path, "rb") as f:
        files = {"file": (filename, f, "application/octet-stream")}
        headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_TOKEN')}"}
        resp = requests.post(STAMP_DETECTION_API, files=files, headers=headers)

    if resp.status_code != 200:
        raise RuntimeError(f"Stamp detection API failed: {resp.text}")

    state["stamp_detection"] = resp.json()
    return state