mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
30 lines
25 KiB
Python
30 lines
25 KiB
Python
|
import unittest
|
||
|
import pathlib
|
||
|
import gradio as gr
|
||
|
from PIL import Image
|
||
|
|
||
|
base_64_test_img = "data:image/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wgARCAEAAQADASIAAhEBAxEB/8QAGwAAAgMBAQEAAAAAAAAAAAAABAUCAwYHAQD/xAAYAQADAQEAAAAAAAAAAAAAAAABAgMABP/aAAwDAQACEAMQAAABYyjLk6Z3Vy2trsiDbGEkeyyizNf7UtdS7MkAy7uGLXunR2PNGm22DgYjITvjFNNDCDBOrejbcpreoLRZMkTHZhGms7oPl9vPUX76LAu6u9SPEmAf6s4A5UhIsBygG+SMmSkdpKzX+6uvm6B9NnM+w6haEzpIGwWDD6idKtlMducM6l3RvKTjdYG6LfSTGgQ54dFvIAIGtkCQQwTsMcrC/fU892awtydiCm0XSoPRgq+ebSUMrzZZMp10y5vya0NYfi9JGlOV6x4u5Iwe87rPfrXSVH3BissOUNfXSdE5e7DGeEMMxitAxR2uVOZc9mZ6b2s8Y+A0Gz7IOTiEVKjUxtiHXwG26Q+MLwX6m0qeFBfC4c2yvVE1AVl9rhl2mkuGpnn2d+YbEvKvAWlMVW2U0CnZ811QjPMq2nAAY9XNqCQoKc3esZh5lwp5rzyfTcc6A6vHMSuhvy1gG+IzL55yXt6nXN4XpOGnT32vzqlK8UkkabIlHUxaLUdy2GNky8B2om+YdxX9XPo78BoCvuwQsZ0XFiFSo0SsVGCl9i9cwd/Trlhfj5HEnpmVYrclpELhP5KV18iXScc1AcK6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EexydirHIvSVWKB/xnfp0HUpYI1nJT7klYrnFKBBv6fv969L6flZXW2Poua9Ae4lyOIkXfHAk0/ZqD+LKZ7JJ7IcjJ5jCnFG/LC/CIzVeNnqJenuJZpKTXhbsITscg/jhd+zKxJ4okQH5U6JzeF/Qf3ykHkUPgGKua9RRl30Igkmzzc38SEho2Pk4uXyV5jhHq38cPZT7Azr2EqheXmjuPxq6SUeNom0OZsqiH8Gi/KeqQId+83oF88nvvgk2LA6TpgXNjfkCSWG74nZRycn5J89/XEWuuA7m9dLoV36SRiRJeztL2pQjSkKZ9MDL1hvWDNIx3JTXvPAcX2T8k450qb2wIzZ1JVSbI/lnCgPpt7ZJHyzJk7l21695XbU1e73l7jtebUv3Ko5sajsS7yrN42vTayK8uWbJDb2h+eOT8VcDIpN58kjQuS/lXIY+tS2Fjz7kCrvoGkxp87YJH8VosQ/919Bfn9ROQa85aWeQnGPRjPoR2ehll62bE5KrM2E5AO0EY2aqlcCe4k0f1NIEjkczWRY0GtSyBrKoYyHjnH4tJ3aNdEQ9jK0cFazKTmvW8/+h/VchbpF1/8APKO0pQ9Cus1tNZrANnfRqa9pIUOF+oScaa0qLdslxGD4zPFHhWxYMNOcYtWXpamLlBoRHbeut/4dc+cGfsn8ToBm1F2zr7oU5rUi8AQsnF9Vmg0ZoNAey/tuHQO0sYyckB5JSYa88xsRiCvHTJytSiGaVB23gTWP06r7ZFG1ky/KSZSQyjEVcOHQxvkYfxHB8YthdLBE8xOb2PtUD8z6jJ9Zxto15v8AJVGySOvIHjsqBBbkEVPrkVMEAdc8fZTEEwnY77wHZYkNx9U/bT1XOP8A7RvIx7/fxnwwbZ4ysb1tAIopvYbsBFON2LyhbANiMcXNuPjSHh4usMgo1UzwxgdAM8YI8WhGXXNiQdUy2eq+Qg71kc3riIGv2
|
||
|
|
||
|
class ImagePreprocessing(unittest.TestCase):
|
||
|
def test_decode_base64_to_image(self):
|
||
|
output_image = gr.processing_utils.decode_base64_to_image(
|
||
|
base_64_test_img)
|
||
|
self.assertIsInstance(output_image, Image.Image)
|
||
|
|
||
|
def test_encode_url_or_file_to_base64(self):
|
||
|
output_base64 = gr.processing_utils.encode_url_or_file_to_base64(
|
||
|
"images/lion.jpg")
|
||
|
self.assertEquals(output_base64, base_64_test_img)
|
||
|
|
||
|
def test_encode_file_to_base64(self):
|
||
|
output_base64 = gr.processing_utils.encode_file_to_base64(
|
||
|
"images/lion.jpg")
|
||
|
self.assertEquals(output_base64, base_64_test_img)
|
||
|
|
||
|
def test_encode_url_to_base64(self):
|
||
|
output_base64 = gr.processing_utils.encode_url_to_base64("https://raw.githubusercontent.com/gradio-app/gradio/master/test/images/lion.jpg")
|
||
|
self.assertEqual(output_base64, base_64_test_img)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
unittest.main()
|