flexbox_webpage.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can generate an HTML file using flexbox"
  3. TAGS = ['code', 'html']
  4. question = """
  5. Generate an HTML file that uses flexbox to create a webpage with a header 200px at the top (colored red), and the rest of the body split 100px for a left sidebar (in blue), 100px for a right sidebar (in green), and the rest of the page in the middle (in white).
  6. """
  7. def check(x):
  8. import io
  9. from PIL import Image
  10. import numpy as np
  11. img = Image.open(io.BytesIO(x))
  12. np_img = np.array(img)[:,:,:3]
  13. while np.mean(np_img[0]) >= 254:
  14. np_img = np_img[1:]
  15. while np.mean(np_img[:, 0]) >= 254:
  16. np_img = np_img[:, 1:]
  17. if np_img[0:200].std((0,1)).mean() > 20:
  18. return False
  19. if np_img[400:, :100].std((0,1)).mean() > 20:
  20. return False
  21. if np_img[400:, -100:-30].std((0,1)).mean() > 20:
  22. return False
  23. if np_img[0:200].mean((0,1)).argmax() != 0:
  24. return False
  25. if np_img[400:, :100].mean((0,1)).argmax() != 2:
  26. return False
  27. if np_img[400:, -100:].mean((0,1)).argmax() != 1:
  28. return False
  29. if np_img[:800, :100].std((0,1)).mean() < 20:
  30. return False
  31. if np_img[:800, -100:].std((0,1)).mean() < 20:
  32. return False
  33. return True
  34. TestFlexbox = question >> LLMRun() >> ExtractCode(keep_main=True, lang="html/javascript") >> SeleniumDraw() >> PyFunc(check)
  35. if __name__ == "__main__":
  36. print(run_test(TestFlexbox))