File size: 1,215 Bytes
80526f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
ตัวอย่างเรียก API ทั้ง 3 endpoint ของ Space
ติดตั้ง: pip install gradio_client
แก้ SPACE_ID เป็นของคุณ เช่น "username/boneage-prediction"
"""
from gradio_client import Client, handle_file

SPACE_ID = "your-username/boneage-prediction"   # <-- แก้ตรงนี้
# private space: Client(SPACE_ID, hf_token="hf_xxx")

client = Client(SPACE_ID)
img = handle_file("test_hand.png")   # path หรือ URL

# --- API 1: Bone Age ---
bone_age = client.predict(image=img, sex="male", api_name="/bone_age")
print("Bone Age:", bone_age)
# {'bone_age_months': 132.4, 'bone_age_years': 11.03, 'readable': '11 ปี 0 เดือน', 'sex': 'male'}

# --- API 2: Confidence Interval ---
ci = client.predict(image=img, sex="male", k=1.0, api_name="/confidence_interval")
print("CI:", ci)
# {'mean_months': 132.4, 'sd_months': 8.7, 'k': 1.0,
#  'lower_months': 123.7, 'upper_months': 141.1, 'interval_str': '132.40 ± 8.70 เดือน'}

# --- API 3: Grad-CAM (คืน path ไฟล์รูป overlay) ---
cam_path = client.predict(image=img, sex="male", api_name="/gradcam")
print("Grad-CAM saved at:", cam_path)