File size: 1,541 Bytes
e429fc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b90f0c8
 
 
e429fc6
b90f0c8
e429fc6
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import base64
import os
import io

import gradio as gr
import requests
from PIL import Image

api_host = os.getenv('API_HOST', 'http://localhost:8005')


def assess_image(img):
    pil_image = Image.fromarray(img.astype('uint8'), 'RGB')
    byte_arr = io.BytesIO()
    pil_image.save(byte_arr, format='PNG')

    gpt4o_url = f'{api_host}/v1/qc/gpt4o'
    gemini_pro_url = f'{api_host}/v1/qc/gemini-pro'

    request1 = requests.post(gpt4o_url, files={'file': byte_arr.getvalue()})
    request2 = requests.post(gemini_pro_url, files={'file': byte_arr.getvalue()})

    return dict(request1.json()), dict(request2.json())


def assess_colour_accuracy(img1, img2):
    pil_img1 = Image.fromarray(img1.astype('uint8'), 'RGB')
    pil_img2 = Image.fromarray(img2.astype('uint8'), 'RGB')

    byte_arr1 = io.BytesIO()
    byte_arr2 = io.BytesIO()

    pil_img1.save(byte_arr1, format='PNG')
    pil_img2.save(byte_arr2, format='PNG')

    qc_color_url = f'{api_host}/v1/qc/garment-color'

    response = requests.post(qc_color_url, files={'file_1': byte_arr1.getvalue(), 'file_2': byte_arr2.getvalue()})

    return str(response.text)


iface1 = gr.Interface(fn=assess_image, inputs="image", outputs=[gr.JSON(label='GPT4o'), gr.JSON(label='Gemini Pro 1.5')])
# iface2 = gr.Interface(fn=assess_colour_accuracy,
#                       inputs=[gr.Image(label='Image'), gr.Image(label='Reference image')],
#                       outputs=gr.Textbox(label='Response'))

demo = gr.TabbedInterface([iface1], ["Image Quality Assessment"])
demo.launch()