Repository: gradio-app/gradio
Pull request:  Add a 'None' option to the gradio.Image component to disable image_m…
Add a 'None' option to the gradio.Image component to disable image_mode conversion. This commit will avoid convert behavior in prepress phase forcefully.

Closes: https://github.com/gradio-app/gradio/issues/9222

Problem statement:
I don't want to convert uploaded image to image_mode forcedly when using Gradio.Image
Gradio.Image component has image_mode parameters to force uploaded image to convert RGB\RGBA and etc, if I want to keep raw image mode, how should I do? if image_mode can add a option, I think it is useful.

Hints from issue discussion:
Thanks @GeeMoose, this makes sense to me. We could allow `image_mode` to take a `None` value in which case its inferred from the file itself. Would you like to open a PR for this? 
if gradio organization allows, I am glad to do it.
Yes, please go for it! Happy to review once the PR is open
The main file to edit would be: https://github.com/gradio-app/gradio/blob/41d5ab987ba9728753be4509490c79041655809b/gradio/components/image.py

Commit message:  Add a 'None' option to the gradio.Image component to disable image_mode conversion behavior

Patch to review:
diff --git a/gradio/components/image.py b/gradio/components/image.py
index 695949b819..b756de6f63 100644
--- a/gradio/components/image.py
+++ b/gradio/components/image.py
@@ -51,7 +51,7 @@ def __init__(
         height: int | str | None = None,
         width: int | str | None = None,
         image_mode: Literal[
-            "1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F"
+            "1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F", "None"
         ] = "RGB",
         sources: list[Literal["upload", "webcam", "clipboard"]]
         | Literal["upload", "webcam", "clipboard"]
@@ -199,7 +199,8 @@ def preprocess(
         if suffix.lower() != "gif" and im is not None:
             with warnings.catch_warnings():
                 warnings.simplefilter("ignore")
-                im = im.convert(self.image_mode)
+                if self.image_mode != "None":
+                    im = im.convert(self.image_mode)
         return image_utils.format_image(
             im,
             cast(Literal["numpy", "pil", "filepath"], self.type),


Code review comments:
diff_hunk: @@ -51,7 +51,7 @@ def __init__(
         height: int | str | None = None,
         width: int | str | None = None,
         image_mode: Literal[
-            "1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F"
+            "1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F", "None"
path: gradio/components/image.py
text: @user1:
This should be `Literal["1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F"] | None`, instead of the string "None"

diff_hunk: @@ -199,7 +199,8 @@ def preprocess(
         if suffix.lower() != "gif" and im is not None:
             with warnings.catch_warnings():
                 warnings.simplefilter("ignore")
-                im = im.convert(self.image_mode)
+                if self.image_mode != "None":
path: gradio/components/image.py
text: @user1:
```suggestion
                if self.image_mode is not None:
```