Avoid using torch's Tensor or PIL's Image in chat template utils if not available
Author: RezaRahemtola
Pull request: yes

# What does this PR do?

This PR adds conditional checks to the types mapping definitions to avoid defining types that are conditionally imported previously, if the same check doesn't succeed.

This allows a user (like me) to use `transformers` for simple stuff like [tokenizers](https://huggingface.co/docs/transformers/fast_tokenizers#use-tokenizers-from--tokenizers) without needed to install PIL and/or torch if not needed (I'm not using the [tokenizers](https://pypi.org/project/tokenizers/) library directly as it doesn't include chat templating functions, and I'm not using torch/tensorflow/JAX as I'm just calling models run locally with llamacpp, installing one of those just for chat templating seems overkill).

Before, a simple call to `tokenizer.apply_chat_template` would result in this error:
```text
  File "...../venv/lib/python3.11/site-packages/transformers/utils/chat_template_utils.py", line 79, in _get_json_schema_type
    Image: {"type": "image"},
    ^^^^^
NameError: name 'Image' is not defined
```

With this fix, there's not error: if PIL (or torch) isn't installed, it's [not imported](https://github.com/huggingface/transformers/blob/fa3f2db5c7405a742fcb8f686d3754f70db00977/src/transformers/utils/chat_template_utils.py#L35) (already the case) and not used (added here).

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

- tokenizers: @ArthurZucker
- chat templates: @Rocketknight1







Comments:
Also cc @zucchini-nlp 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_34165). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@zucchini-nlp @LysandreJik this PR is quite straightforward, and I think it's okay to accept - are you okay with me merging it once tests pass?

I am not qualified for review here, so whatever you find reasonable @Rocketknight1  :)

~In that case, since this is a simple bugfix, I think it's okay to merge. One last step, though - @RezaRahemtola can you fix up the code quality tests? To do that:~

~1) `pip install transformers[quality]`~
~2) `make style` in the transformers directory~
~3) commit and push~

Never mind - this is actually a CI issue. Rerunning it, you don't need to do anything @RezaRahemtola !

Documentation build is failing but this PR doesn't touch the docs at all, so I'm assuming that's an issue with the doc builder. Merging, and thanks @RezaRahemtola for the PR!