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()