hanhpv commited on
Commit
e429fc6
·
verified ·
1 Parent(s): 9c50cef

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import os
3
+ import io
4
+
5
+ import gradio as gr
6
+ import requests
7
+ from PIL import Image
8
+
9
+ api_host = os.getenv('API_HOST', 'http://localhost:8005')
10
+
11
+
12
+ def assess_image(img):
13
+ pil_image = Image.fromarray(img.astype('uint8'), 'RGB')
14
+ byte_arr = io.BytesIO()
15
+ pil_image.save(byte_arr, format='PNG')
16
+
17
+ gpt4o_url = f'{api_host}/v1/qc/gpt4o'
18
+ gemini_pro_url = f'{api_host}/v1/qc/gemini-pro'
19
+
20
+ request1 = requests.post(gpt4o_url, files={'file': byte_arr.getvalue()})
21
+ request2 = requests.post(gemini_pro_url, files={'file': byte_arr.getvalue()})
22
+
23
+ return dict(request1.json()), dict(request2.json())
24
+
25
+
26
+ def assess_colour_accuracy(img1, img2):
27
+ pil_img1 = Image.fromarray(img1.astype('uint8'), 'RGB')
28
+ pil_img2 = Image.fromarray(img2.astype('uint8'), 'RGB')
29
+
30
+ byte_arr1 = io.BytesIO()
31
+ byte_arr2 = io.BytesIO()
32
+
33
+ pil_img1.save(byte_arr1, format='PNG')
34
+ pil_img2.save(byte_arr2, format='PNG')
35
+
36
+ qc_color_url = f'{api_host}/v1/qc/garment-color'
37
+
38
+ response = requests.post(qc_color_url, files={'file_1': byte_arr1.getvalue(), 'file_2': byte_arr2.getvalue()})
39
+
40
+ return str(response.text)
41
+
42
+
43
+ iface1 = gr.Interface(fn=assess_image, inputs="image", outputs=[gr.JSON(label='GPT4o'), gr.JSON(label='Gemini Pro 1.5')])
44
+ iface2 = gr.Interface(fn=assess_colour_accuracy,
45
+ inputs=[gr.Image(label='Image'), gr.Image(label='Reference image')],
46
+ outputs=gr.Textbox(label='Response'))
47
+
48
+ demo = gr.TabbedInterface([iface1, iface2], ["Image Quality Assessment", "Colour Match Assessment"])
49
+ demo.launch()
50
+