extras_test.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import os
  2. import unittest
  3. import requests
  4. from gradio.processing_utils import encode_pil_to_base64
  5. from PIL import Image
  6. from modules.paths import script_path
  7. class TestExtrasWorking(unittest.TestCase):
  8. def setUp(self):
  9. self.url_extras_single = "http://localhost:7860/sdapi/v1/extra-single-image"
  10. self.extras_single = {
  11. "resize_mode": 0,
  12. "show_extras_results": True,
  13. "gfpgan_visibility": 0,
  14. "codeformer_visibility": 0,
  15. "codeformer_weight": 0,
  16. "upscaling_resize": 2,
  17. "upscaling_resize_w": 128,
  18. "upscaling_resize_h": 128,
  19. "upscaling_crop": True,
  20. "upscaler_1": "None",
  21. "upscaler_2": "None",
  22. "extras_upscaler_2_visibility": 0,
  23. "image": encode_pil_to_base64(Image.open(os.path.join(script_path, r"test/test_files/img2img_basic.png")))
  24. }
  25. def test_simple_upscaling_performed(self):
  26. self.extras_single["upscaler_1"] = "Lanczos"
  27. self.assertEqual(requests.post(self.url_extras_single, json=self.extras_single).status_code, 200)
  28. class TestPngInfoWorking(unittest.TestCase):
  29. def setUp(self):
  30. self.url_png_info = "http://localhost:7860/sdapi/v1/extra-single-image"
  31. self.png_info = {
  32. "image": encode_pil_to_base64(Image.open(os.path.join(script_path, r"test/test_files/img2img_basic.png")))
  33. }
  34. def test_png_info_performed(self):
  35. self.assertEqual(requests.post(self.url_png_info, json=self.png_info).status_code, 200)
  36. class TestInterrogateWorking(unittest.TestCase):
  37. def setUp(self):
  38. self.url_interrogate = "http://localhost:7860/sdapi/v1/extra-single-image"
  39. self.interrogate = {
  40. "image": encode_pil_to_base64(Image.open(os.path.join(script_path, r"test/test_files/img2img_basic.png"))),
  41. "model": "clip"
  42. }
  43. def test_interrogate_performed(self):
  44. self.assertEqual(requests.post(self.url_interrogate, json=self.interrogate).status_code, 200)
  45. if __name__ == "__main__":
  46. unittest.main()