prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Invalid filename for blank resources
  When downloading a resource that is blank, the filename is `Sorting Network (0 to -1).pdf`.
  
  The filename should be something like `Sorting Network (blank).pdf`.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `csunplugged/resources/views/sorting_network.py`
  Content:
  ```
  1 from PIL import Image, ImageDraw, ImageFont
  2 from random import sample
  3 
  4 
  5 def resource_image(get_request, resource):
  6     """Creates a image for Sorting Network resource.
  7 
  8     Returns:
  9         A Pillow image object.
  10     """
  11     image_path = 'static/img/resource-sorting-network-colour.png'
  12     image = Image.open(image_path)
  13     draw = ImageDraw.Draw(image)
  14 
  15     (range_min, range_max, font_size) = number_range(get_request)
  16 
  17     font_path = 'static/fonts/PatrickHand-Regular.ttf'
  18 
  19     # Add numbers to text if needed
  20     if get_request['prefilled_values'] != 'blank':
  21         font = ImageFont.truetype(font_path, font_size)
  22         numbers = sample(range(range_min, range_max), 6)
  23         base_coord_x = 70
  24         base_coord_y = 2560
  25         coord_x_increment = 204
  26         for number in numbers:
  27             text = str(number)
  28             text_width, text_height = draw.textsize(text, font=font)
  29             coord_x = base_coord_x - (text_width / 2)
  30             coord_y = base_coord_y - (text_height / 2)
  31             draw.text(
  32                 (coord_x, coord_y),
  33                 text,
  34                 font=font,
  35                 fill='#000'
  36             )
  37             base_coord_x += coord_x_increment
  38 
  39     return image
  40 
  41 
  42 def subtitle(get_request, resource):
  43     """Returns the subtitle string of the resource.
  44 
  45     Used after the resource name in the filename, and
  46     also on the resource image.
  47     """
  48     SUBTITLE_TEMPLATE = '{} to {}'
  49     range_min, range_max, font_size = number_range(get_request)
  50     text = SUBTITLE_TEMPLATE.format(range_min, range_max - 1)
  51     return text
  52 
  53 
  54 def number_range(get_request):
  55     """Returns a tuple of (range_min, range_max, font_size)
  56     for the requested resource.
  57     """
  58     prefilled_values = get_request['prefilled_values']
  59     range_min = 0
  60     range_max = 0
  61     font_size = 150
  62     if prefilled_values == 'easy':
  63         range_min = 1
  64         range_max = 10
  65     elif prefilled_values == 'medium':
  66         range_min = 10
  67         range_max = 100
  68         font_size = 120
  69     elif prefilled_values == 'hard':
  70         range_min = 100
  71         range_max = 1000
  72         font_size = 90
  73     return (range_min, range_max, font_size)
  74
  ```
  
  Path: `csunplugged/resources/views/treasure_hunt.py`
  Content:
  ```
  1 from PIL import Image, ImageDraw, ImageFont
  2 from random import sample
  3 
  4 
  5 def resource_image(get_request, resource):
  6     """Creates a image for Treasure Hunt resource.
  7 
  8     Returns:
  9         A Pillow image object.
  10     """
  11     image_path = 'static/img/resource-treasure-hunt.png'
  12     font_path = 'static/fonts/PatrickHand-Regular.ttf'
  13     image = Image.open(image_path)
  14     draw = ImageDraw.Draw(image)
  15 
  16     (range_min, range_max, font_size) = number_range(get_request)
  17 
  18     # Add numbers to image if required
  19     if get_request['prefilled_values'] != 'blank':
  20         font = ImageFont.truetype(font_path, font_size)
  21 
  22         total_numbers = 26
  23         numbers = sample(range(range_min, range_max), total_numbers)
  24         if get_request['number_order'] == 'sorted':
  25             numbers.sort()
  26 
  27         starting_coord_y = 494
  28         base_coord_y = starting_coord_y
  29         coord_y_increment = 286
  30         base_coords_x = [257, 692]
  31         for i in range(0, total_numbers):
  32             text = str(numbers[i])
  33             text_width, text_height = draw.textsize(text, font=font)
  34 
  35             coord_x = base_coords_x[i % 2] - (text_width / 2)
  36             coord_y = base_coord_y - (text_height / 2)
  37             if i % 2 == 1:
  38                 coord_y -= 10
  39                 base_coord_y += coord_y_increment
  40             draw.text(
  41                 (coord_x, coord_y),
  42                 text,
  43                 font=font,
  44                 fill='#000'
  45             )
  46 
  47         # Add number order and range text
  48         text = subtitle(get_request, resource)
  49         font = ImageFont.truetype(font_path, 110)
  50         text_width, text_height = draw.textsize(text, font=font)
  51         coord_x = 1472 - (text_width / 2)
  52         coord_y = 35 - (text_height / 2)
  53         draw.text(
  54             (coord_x, coord_y),
  55             text,
  56             font=font,
  57             fill='#000'
  58         )
  59 
  60     return image
  61 
  62 
  63 def subtitle(get_request, resource):
  64     """Returns the subtitle string of the resource.
  65 
  66     Used after the resource name in the filename, and
  67     also on the resource image.
  68     """
  69     SUBTITLE_TEMPLATE = '{} - {} to {}'
  70     number_order_text = get_request['number_order'].title()
  71     range_min, range_max, font_size = number_range(get_request)
  72     text = SUBTITLE_TEMPLATE.format(number_order_text, range_min, range_max - 1)
  73     return text
  74 
  75 
  76 def number_range(get_request):
  77     """Returns a tuple of (range_min, range_max, font_size)
  78     for the requested resource.
  79     """
  80     prefilled_values = get_request['prefilled_values']
  81     range_min = 0
  82     if prefilled_values == 'easy':
  83         range_max = 100
  84         font_size = 97
  85     elif prefilled_values == 'medium':
  86         range_max = 1000
  87         font_size = 80
  88     elif prefilled_values == 'hard':
  89         range_max = 10000
  90         font_size = 70
  91     return (range_min, range_max, font_size)
  92
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/csunplugged/resources/views/sorting_network.py b/csunplugged/resources/views/sorting_network.py
  --- a/csunplugged/resources/views/sorting_network.py
  +++ b/csunplugged/resources/views/sorting_network.py
  @@ -45,9 +45,12 @@
       Used after the resource name in the filename, and
       also on the resource image.
       """
  -    SUBTITLE_TEMPLATE = '{} to {}'
  -    range_min, range_max, font_size = number_range(get_request)
  -    text = SUBTITLE_TEMPLATE.format(range_min, range_max - 1)
  +    if get_request['prefilled_values'] == 'blank':
  +        text = 'blank'
  +    else:
  +        SUBTITLE_TEMPLATE = '{} to {}'
  +        range_min, range_max, font_size = number_range(get_request)
  +        text = SUBTITLE_TEMPLATE.format(range_min, range_max - 1)
       return text
   
   
  diff --git a/csunplugged/resources/views/treasure_hunt.py b/csunplugged/resources/views/treasure_hunt.py
  --- a/csunplugged/resources/views/treasure_hunt.py
  +++ b/csunplugged/resources/views/treasure_hunt.py
  @@ -13,10 +13,9 @@
       image = Image.open(image_path)
       draw = ImageDraw.Draw(image)
   
  -    (range_min, range_max, font_size) = number_range(get_request)
  -
       # Add numbers to image if required
       if get_request['prefilled_values'] != 'blank':
  +        (range_min, range_max, font_size) = number_range(get_request)
           font = ImageFont.truetype(font_path, font_size)
   
           total_numbers = 26
  @@ -66,10 +65,13 @@
       Used after the resource name in the filename, and
       also on the resource image.
       """
  -    SUBTITLE_TEMPLATE = '{} - {} to {}'
  -    number_order_text = get_request['number_order'].title()
  -    range_min, range_max, font_size = number_range(get_request)
  -    text = SUBTITLE_TEMPLATE.format(number_order_text, range_min, range_max - 1)
  +    if get_request['prefilled_values'] == 'blank':
  +        text = 'blank'
  +    else:
  +        SUBTITLE_TEMPLATE = '{} - {} to {}'
  +        number_order_text = get_request['number_order'].title()
  +        range_min, range_max, font_size = number_range(get_request)
  +        text = SUBTITLE_TEMPLATE.format(number_order_text, range_min, range_max - 1)
       return text
  
verification_info: {"golden_diff": "diff --git a/csunplugged/resources/views/sorting_network.py b/csunplugged/resources/views/sorting_network.py\n--- a/csunplugged/resources/views/sorting_network.py\n+++ b/csunplugged/resources/views/sorting_network.py\n@@ -45,9 +45,12 @@\n     Used after the resource name in the filename, and\n     also on the resource image.\n     \"\"\"\n-    SUBTITLE_TEMPLATE = '{} to {}'\n-    range_min, range_max, font_size = number_range(get_request)\n-    text = SUBTITLE_TEMPLATE.format(range_min, range_max - 1)\n+    if get_request['prefilled_values'] == 'blank':\n+        text = 'blank'\n+    else:\n+        SUBTITLE_TEMPLATE = '{} to {}'\n+        range_min, range_max, font_size = number_range(get_request)\n+        text = SUBTITLE_TEMPLATE.format(range_min, range_max - 1)\n     return text\n \n \ndiff --git a/csunplugged/resources/views/treasure_hunt.py b/csunplugged/resources/views/treasure_hunt.py\n--- a/csunplugged/resources/views/treasure_hunt.py\n+++ b/csunplugged/resources/views/treasure_hunt.py\n@@ -13,10 +13,9 @@\n     image = Image.open(image_path)\n     draw = ImageDraw.Draw(image)\n \n-    (range_min, range_max, font_size) = number_range(get_request)\n-\n     # Add numbers to image if required\n     if get_request['prefilled_values'] != 'blank':\n+        (range_min, range_max, font_size) = number_range(get_request)\n         font = ImageFont.truetype(font_path, font_size)\n \n         total_numbers = 26\n@@ -66,10 +65,13 @@\n     Used after the resource name in the filename, and\n     also on the resource image.\n     \"\"\"\n-    SUBTITLE_TEMPLATE = '{} - {} to {}'\n-    number_order_text = get_request['number_order'].title()\n-    range_min, range_max, font_size = number_range(get_request)\n-    text = SUBTITLE_TEMPLATE.format(number_order_text, range_min, range_max - 1)\n+    if get_request['prefilled_values'] == 'blank':\n+        text = 'blank'\n+    else:\n+        SUBTITLE_TEMPLATE = '{} - {} to {}'\n+        number_order_text = get_request['number_order'].title()\n+        range_min, range_max, font_size = number_range(get_request)\n+        text = SUBTITLE_TEMPLATE.format(number_order_text, range_min, range_max - 1)\n     return text\n", "issue": "Invalid filename for blank resources\nWhen downloading a resource that is blank, the filename is `Sorting Network (0 to -1).pdf`.\r\n\r\nThe filename should be something like `Sorting Network (blank).pdf`.\r\n\n", "before_files": [{"content": "from PIL import Image, ImageDraw, ImageFont\nfrom random import sample\n\n\ndef resource_image(get_request, resource):\n    \"\"\"Creates a image for Sorting Network resource.\n\n    Returns:\n        A Pillow image object.\n    \"\"\"\n    image_path = 'static/img/resource-sorting-network-colour.png'\n    image = Image.open(image_path)\n    draw = ImageDraw.Draw(image)\n\n    (range_min, range_max, font_size) = number_range(get_request)\n\n    font_path = 'static/fonts/PatrickHand-Regular.ttf'\n\n    # Add numbers to text if needed\n    if get_request['prefilled_values'] != 'blank':\n        font = ImageFont.truetype(font_path, font_size)\n        numbers = sample(range(range_min, range_max), 6)\n        base_coord_x = 70\n        base_coord_y = 2560\n        coord_x_increment = 204\n        for number in numbers:\n            text = str(number)\n            text_width, text_height = draw.textsize(text, font=font)\n            coord_x = base_coord_x - (text_width / 2)\n            coord_y = base_coord_y - (text_height / 2)\n            draw.text(\n                (coord_x, coord_y),\n                text,\n                font=font,\n                fill='#000'\n            )\n            base_coord_x += coord_x_increment\n\n    return image\n\n\ndef subtitle(get_request, resource):\n    \"\"\"Returns the subtitle string of the resource.\n\n    Used after the resource name in the filename, and\n    also on the resource image.\n    \"\"\"\n    SUBTITLE_TEMPLATE = '{} to {}'\n    range_min, range_max, font_size = number_range(get_request)\n    text = SUBTITLE_TEMPLATE.format(range_min, range_max - 1)\n    return text\n\n\ndef number_range(get_request):\n    \"\"\"Returns a tuple of (range_min, range_max, font_size)\n    for the requested resource.\n    \"\"\"\n    prefilled_values = get_request['prefilled_values']\n    range_min = 0\n    range_max = 0\n    font_size = 150\n    if prefilled_values == 'easy':\n        range_min = 1\n        range_max = 10\n    elif prefilled_values == 'medium':\n        range_min = 10\n        range_max = 100\n        font_size = 120\n    elif prefilled_values == 'hard':\n        range_min = 100\n        range_max = 1000\n        font_size = 90\n    return (range_min, range_max, font_size)\n", "path": "csunplugged/resources/views/sorting_network.py"}, {"content": "from PIL import Image, ImageDraw, ImageFont\nfrom random import sample\n\n\ndef resource_image(get_request, resource):\n    \"\"\"Creates a image for Treasure Hunt resource.\n\n    Returns:\n        A Pillow image object.\n    \"\"\"\n    image_path = 'static/img/resource-treasure-hunt.png'\n    font_path = 'static/fonts/PatrickHand-Regular.ttf'\n    image = Image.open(image_path)\n    draw = ImageDraw.Draw(image)\n\n    (range_min, range_max, font_size) = number_range(get_request)\n\n    # Add numbers to image if required\n    if get_request['prefilled_values'] != 'blank':\n        font = ImageFont.truetype(font_path, font_size)\n\n        total_numbers = 26\n        numbers = sample(range(range_min, range_max), total_numbers)\n        if get_request['number_order'] == 'sorted':\n            numbers.sort()\n\n        starting_coord_y = 494\n        base_coord_y = starting_coord_y\n        coord_y_increment = 286\n        base_coords_x = [257, 692]\n        for i in range(0, total_numbers):\n            text = str(numbers[i])\n            text_width, text_height = draw.textsize(text, font=font)\n\n            coord_x = base_coords_x[i % 2] - (text_width / 2)\n            coord_y = base_coord_y - (text_height / 2)\n            if i % 2 == 1:\n                coord_y -= 10\n                base_coord_y += coord_y_increment\n            draw.text(\n                (coord_x, coord_y),\n                text,\n                font=font,\n                fill='#000'\n            )\n\n        # Add number order and range text\n        text = subtitle(get_request, resource)\n        font = ImageFont.truetype(font_path, 110)\n        text_width, text_height = draw.textsize(text, font=font)\n        coord_x = 1472 - (text_width / 2)\n        coord_y = 35 - (text_height / 2)\n        draw.text(\n            (coord_x, coord_y),\n            text,\n            font=font,\n            fill='#000'\n        )\n\n    return image\n\n\ndef subtitle(get_request, resource):\n    \"\"\"Returns the subtitle string of the resource.\n\n    Used after the resource name in the filename, and\n    also on the resource image.\n    \"\"\"\n    SUBTITLE_TEMPLATE = '{} - {} to {}'\n    number_order_text = get_request['number_order'].title()\n    range_min, range_max, font_size = number_range(get_request)\n    text = SUBTITLE_TEMPLATE.format(number_order_text, range_min, range_max - 1)\n    return text\n\n\ndef number_range(get_request):\n    \"\"\"Returns a tuple of (range_min, range_max, font_size)\n    for the requested resource.\n    \"\"\"\n    prefilled_values = get_request['prefilled_values']\n    range_min = 0\n    if prefilled_values == 'easy':\n        range_max = 100\n        font_size = 97\n    elif prefilled_values == 'medium':\n        range_max = 1000\n        font_size = 80\n    elif prefilled_values == 'hard':\n        range_max = 10000\n        font_size = 70\n    return (range_min, range_max, font_size)\n", "path": "csunplugged/resources/views/treasure_hunt.py"}], "after_files": [{"content": "from PIL import Image, ImageDraw, ImageFont\nfrom random import sample\n\n\ndef resource_image(get_request, resource):\n    \"\"\"Creates a image for Sorting Network resource.\n\n    Returns:\n        A Pillow image object.\n    \"\"\"\n    image_path = 'static/img/resource-sorting-network-colour.png'\n    image = Image.open(image_path)\n    draw = ImageDraw.Draw(image)\n\n    (range_min, range_max, font_size) = number_range(get_request)\n\n    font_path = 'static/fonts/PatrickHand-Regular.ttf'\n\n    # Add numbers to text if needed\n    if get_request['prefilled_values'] != 'blank':\n        font = ImageFont.truetype(font_path, font_size)\n        numbers = sample(range(range_min, range_max), 6)\n        base_coord_x = 70\n        base_coord_y = 2560\n        coord_x_increment = 204\n        for number in numbers:\n            text = str(number)\n            text_width, text_height = draw.textsize(text, font=font)\n            coord_x = base_coord_x - (text_width / 2)\n            coord_y = base_coord_y - (text_height / 2)\n            draw.text(\n                (coord_x, coord_y),\n                text,\n                font=font,\n                fill='#000'\n            )\n            base_coord_x += coord_x_increment\n\n    return image\n\n\ndef subtitle(get_request, resource):\n    \"\"\"Returns the subtitle string of the resource.\n\n    Used after the resource name in the filename, and\n    also on the resource image.\n    \"\"\"\n    if get_request['prefilled_values'] == 'blank':\n        text = 'blank'\n    else:\n        SUBTITLE_TEMPLATE = '{} to {}'\n        range_min, range_max, font_size = number_range(get_request)\n        text = SUBTITLE_TEMPLATE.format(range_min, range_max - 1)\n    return text\n\n\ndef number_range(get_request):\n    \"\"\"Returns a tuple of (range_min, range_max, font_size)\n    for the requested resource.\n    \"\"\"\n    prefilled_values = get_request['prefilled_values']\n    range_min = 0\n    range_max = 0\n    font_size = 150\n    if prefilled_values == 'easy':\n        range_min = 1\n        range_max = 10\n    elif prefilled_values == 'medium':\n        range_min = 10\n        range_max = 100\n        font_size = 120\n    elif prefilled_values == 'hard':\n        range_min = 100\n        range_max = 1000\n        font_size = 90\n    return (range_min, range_max, font_size)\n", "path": "csunplugged/resources/views/sorting_network.py"}, {"content": "from PIL import Image, ImageDraw, ImageFont\nfrom random import sample\n\n\ndef resource_image(get_request, resource):\n    \"\"\"Creates a image for Treasure Hunt resource.\n\n    Returns:\n        A Pillow image object.\n    \"\"\"\n    image_path = 'static/img/resource-treasure-hunt.png'\n    font_path = 'static/fonts/PatrickHand-Regular.ttf'\n    image = Image.open(image_path)\n    draw = ImageDraw.Draw(image)\n\n    # Add numbers to image if required\n    if get_request['prefilled_values'] != 'blank':\n        (range_min, range_max, font_size) = number_range(get_request)\n        font = ImageFont.truetype(font_path, font_size)\n\n        total_numbers = 26\n        numbers = sample(range(range_min, range_max), total_numbers)\n        if get_request['number_order'] == 'sorted':\n            numbers.sort()\n\n        starting_coord_y = 494\n        base_coord_y = starting_coord_y\n        coord_y_increment = 286\n        base_coords_x = [257, 692]\n        for i in range(0, total_numbers):\n            text = str(numbers[i])\n            text_width, text_height = draw.textsize(text, font=font)\n\n            coord_x = base_coords_x[i % 2] - (text_width / 2)\n            coord_y = base_coord_y - (text_height / 2)\n            if i % 2 == 1:\n                coord_y -= 10\n                base_coord_y += coord_y_increment\n            draw.text(\n                (coord_x, coord_y),\n                text,\n                font=font,\n                fill='#000'\n            )\n\n        # Add number order and range text\n        text = subtitle(get_request, resource)\n        font = ImageFont.truetype(font_path, 110)\n        text_width, text_height = draw.textsize(text, font=font)\n        coord_x = 1472 - (text_width / 2)\n        coord_y = 35 - (text_height / 2)\n        draw.text(\n            (coord_x, coord_y),\n            text,\n            font=font,\n            fill='#000'\n        )\n\n    return image\n\n\ndef subtitle(get_request, resource):\n    \"\"\"Returns the subtitle string of the resource.\n\n    Used after the resource name in the filename, and\n    also on the resource image.\n    \"\"\"\n    if get_request['prefilled_values'] == 'blank':\n        text = 'blank'\n    else:\n        SUBTITLE_TEMPLATE = '{} - {} to {}'\n        number_order_text = get_request['number_order'].title()\n        range_min, range_max, font_size = number_range(get_request)\n        text = SUBTITLE_TEMPLATE.format(number_order_text, range_min, range_max - 1)\n    return text\n\n\ndef number_range(get_request):\n    \"\"\"Returns a tuple of (range_min, range_max, font_size)\n    for the requested resource.\n    \"\"\"\n    prefilled_values = get_request['prefilled_values']\n    range_min = 0\n    if prefilled_values == 'easy':\n        range_max = 100\n        font_size = 97\n    elif prefilled_values == 'medium':\n        range_max = 1000\n        font_size = 80\n    elif prefilled_values == 'hard':\n        range_max = 10000\n        font_size = 70\n    return (range_min, range_max, font_size)\n", "path": "csunplugged/resources/views/treasure_hunt.py"}]}