Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import requests
|
|
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
def analyze_images(image1, image2, api_key, org_id):
|
@@ -8,8 +10,6 @@ def analyze_images(image1, image2, api_key, org_id):
|
|
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 |
|
@@ -28,7 +28,12 @@ def analyze_images(image1, image2, api_key, org_id):
|
|
28 |
},
|
29 |
}
|
30 |
|
31 |
-
response = requests.post(url, headers=headers, json=data).json()
|
|
|
|
|
|
|
|
|
|
|
32 |
print(response.keys())
|
33 |
|
34 |
if response['status'] == 'success':
|
@@ -36,19 +41,27 @@ def analyze_images(image1, image2, api_key, org_id):
|
|
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__':
|
|
|
1 |
import requests
|
2 |
+
from PIL import Image
|
3 |
+
import base64
|
4 |
import gradio as gr
|
5 |
|
6 |
def analyze_images(image1, image2, api_key, org_id):
|
|
|
10 |
"Authorization": api_key,
|
11 |
}
|
12 |
|
|
|
|
|
13 |
with open(image1, "rb") as img1_file:
|
14 |
image1_b64 = base64.b64encode(img1_file.read()).decode('utf-8')
|
15 |
|
|
|
28 |
},
|
29 |
}
|
30 |
|
31 |
+
response = requests.post(url, headers=headers, json=data).json()
|
32 |
+
|
33 |
+
if 'entry' not in response.keys():
|
34 |
+
return f"Request failed: {response}"
|
35 |
+
|
36 |
+
response = response['entry']
|
37 |
print(response.keys())
|
38 |
|
39 |
if response['status'] == 'success':
|
|
|
41 |
else:
|
42 |
return f"Request failed: {response['text']}"
|
43 |
|
44 |
+
|
45 |
+
def assign_sample_images():
|
46 |
+
image1 = Image.open('./front.jpg')
|
47 |
+
image2 = Image.open('./right.jpg')
|
48 |
+
return image1, image2
|
49 |
+
|
50 |
with gr.Blocks() as demo:
|
51 |
gr.Markdown("## 画像解析アプリ")
|
52 |
|
53 |
with gr.Row():
|
54 |
+
image1 = gr.Image(type="filepath", label="前からの写真", format='jpeg')
|
55 |
+
image2 = gr.Image(type="filepath", label="右側からの写真", format='jpeg')
|
56 |
|
57 |
api_key = gr.Textbox(label="APIキーを入力")
|
58 |
org_id = gr.Textbox(label="組織IDを入力")
|
59 |
|
60 |
+
sample_button = gr.Button("サンプル画像")
|
61 |
analyze_button = gr.Button("解析", variant='primary')
|
62 |
result = gr.TextArea(label="結果表示")
|
63 |
|
64 |
+
sample_button.click(assign_sample_images, inputs=[], outputs=[image1, image2])
|
65 |
analyze_button.click(analyze_images, inputs=[image1, image2, api_key, org_id], outputs=[result])
|
66 |
|
67 |
if __name__ == '__main__':
|