csmith715 commited on
Commit
a1864b3
·
1 Parent(s): 9415326

API Change

Browse files
Files changed (2) hide show
  1. README.md +10 -8
  2. app.py +3 -3
README.md CHANGED
@@ -23,14 +23,16 @@ A simple REST API around an Ultralytics YOLO model for weld-type detection.
23
  Set a secret named `API_TOKEN` in your Space (Settings ▸ Secrets).
24
  Send requests with `Authorization: Bearer <token>`.
25
 
26
- ### Request options
27
 
28
- Send `path to image`
 
29
 
30
- ### cURL examples
 
 
 
 
 
31
 
32
- **Multipart file:**
33
- ```bash
34
- curl -X POST "https://YOUR-SPACE.hf.space/predict" \
35
- -H "Authorization: Bearer $API_TOKEN" \
36
- -F "file=@sample.jpg"
 
23
  Set a secret named `API_TOKEN` in your Space (Settings ▸ Secrets).
24
  Send requests with `Authorization: Bearer <token>`.
25
 
26
+ ### Python POST (with Requests)
27
 
28
+ ```
29
+ b64_file = base64.b64encode(open("weld-image-file.jpg", "rb").read()).decode()
30
 
31
+ r = requests.post(
32
+ "https://huggingface.co/spaces/csmith715/ais-api/predict",
33
+ headers={"Content-Type":"application/json"},
34
+ json={"image_base64": b64_file}
35
+ )
36
+ print(r.json())
37
 
38
+ ```
 
 
 
 
app.py CHANGED
@@ -33,7 +33,7 @@ class PredictResponse(BaseModel):
33
  detections: dict
34
 
35
  class PredictQuery(BaseModel):
36
- image_base64_path: str
37
 
38
  # -----------------------------
39
  # Utils
@@ -97,8 +97,8 @@ def health():
97
 
98
  @app.post("/predict", response_model=PredictResponse)
99
  def predict(file_data: PredictQuery) -> PredictResponse:
100
- file_path = file_data.image_base64_path
101
- data = base64.b64encode(open(file_path, "rb").read()).decode()
102
  if data is None:
103
  weld_summary = {}
104
  # weld_summary = 'No weld types detected.'
 
33
  detections: dict
34
 
35
  class PredictQuery(BaseModel):
36
+ image_base64: str
37
 
38
  # -----------------------------
39
  # Utils
 
97
 
98
  @app.post("/predict", response_model=PredictResponse)
99
  def predict(file_data: PredictQuery) -> PredictResponse:
100
+ data = file_data.image_base64
101
+ # data = base64.b64encode(open(file_path, "rb").read()).decode()
102
  if data is None:
103
  weld_summary = {}
104
  # weld_summary = 'No weld types detected.'