matsuap commited on
Commit
25c9c68
·
verified ·
1 Parent(s): aa1db31

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +55 -0
  2. front.jpg +0 -0
  3. requirements.txt +1 -0
  4. right.jpg +0 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+
4
+ def analyze_images(image1, image2, api_key, org_id):
5
+ url = f"https://platform.bodygram.com/api/orgs/{org_id}/scans"
6
+
7
+ headers = {
8
+ "Authorization": api_key,
9
+ }
10
+
11
+ import base64
12
+
13
+ with open(image1, "rb") as img1_file:
14
+ image1_b64 = base64.b64encode(img1_file.read()).decode('utf-8')
15
+
16
+ with open(image2, "rb") as img2_file:
17
+ image2_b64 = base64.b64encode(img2_file.read()).decode('utf-8')
18
+
19
+ data = {
20
+ "customScanId": "myFirstScan",
21
+ "photoScan": {
22
+ "age": 29,
23
+ "weight": 54000,
24
+ "height": 1640,
25
+ "gender": "female",
26
+ "frontPhoto": image1_b64,
27
+ "rightPhoto": image2_b64,
28
+ },
29
+ }
30
+
31
+ response = requests.post(url, headers=headers, json=data).json()['entry']
32
+ print(response.keys())
33
+
34
+ if response['status'] == 'success':
35
+ return {key: value for key, value in response.items() if key != 'avatar'}
36
+ else:
37
+ return f"Request failed: {response['text']}"
38
+
39
+ with gr.Blocks() as demo:
40
+ gr.Markdown("## 画像解析アプリ")
41
+
42
+ with gr.Row():
43
+ image1 = gr.Image(type="filepath", label="前からの写真")
44
+ image2 = gr.Image(type="filepath", label="右側からの写真")
45
+
46
+ api_key = gr.Textbox(label="APIキーを入力")
47
+ org_id = gr.Textbox(label="組織IDを入力")
48
+
49
+ analyze_button = gr.Button("解析", variant='primary')
50
+ result = gr.TextArea(label="結果表示")
51
+
52
+ analyze_button.click(analyze_images, inputs=[image1, image2, api_key, org_id], outputs=[result])
53
+
54
+ if __name__ == '__main__':
55
+ demo.launch()
front.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio
right.jpg ADDED