Remove `requests` code
Author: omkar-334
Pull request: yes

# What does this PR do?
Removes `requests` code from setup, src and utils files. 
Fixes #42817 partially

- [x] **Quality checks**: `make fixup` passes with no errors

cc @CoderTCY @Wauplin @Rocketknight1 

notes - 
1. I've removed `requests` from setup/workflow files as well, you might want to check the first commit. 
2. A few formatting fixes like "spacing around operators" got added in as well

Comments:
Hello, I got some issues with the current port to httpx.
I managed to set up huggingface_hub calls using the `set_factory_client()` with my custom httpx Client, and it would be nice if all httpx sessions in transformers rely on the same mechanism.

One way to do it would be for example:

```

from huggingface_hub import get_session

client = get_session()
result = client.post(....)

```

This also concerns some other portions of code (like `safetensors_conversion.py`).
Thank you for your support.


Agree with @guibruand 's suggestion here! It's best to use `huggingface_hub.get_session` and then deal with the returned Client as if it was `httpx` directly. @omkar-334 would you like to give it a try? :pray: 

> Agree with @guibruand 's suggestion here! It's best to use `huggingface_hub.get_session` and then deal with the returned Client as if it was `httpx` directly. @omkar-334 would you like to give it a try? :pray: 

Got it. I'll try using that and let you know!

Thank you very much! :hugs: 

Hey @Wauplin , so I've used `get_session` instead of using `httpx` directly. 
I've called the function once and reused it in the file. Is this appropriate, or should we call `get_session` for each request?
As far as i know, the `get_session` already manages a global client and returns it right?

Thanks

hey @Wauplin , went through your comments, understood the changes i need to make. Thanks for clarifying this.  
Just to be sure, this is what we want - 
 - get_session - HF hub specific requests 
  - httpx - single-file scripts, utilities, examples, local/generic endpoint, convert scripts, loading images
  
  Will make the changes and push soon...
  Thanks!

hey @Wauplin , I've made the changes. 

1. Currently there are only 6 instances where `get_session` is used - and they are all images hosted on HF. is this alright or revert these to `httpx` too?  
2.  Also, in `src/transformers/safetensors_conversion.py`, what should be used? Currently, `httpx` is used for this url - `"https://safetensors-convert.hf.space"`
3. There are a few docstrings where `requests` is used. Since the docs are user-facing, should i let this be as it is, or change it to `httpx` as well?

Thanks!

@bot /style

Style fix is beginning .... [View the workflow run here](https://github.com/huggingface/transformers/actions/runs/21038258341).

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

Hi @omkar-334 sorry getting back to it only now. A few notes:

- Some changes are purely formatting issues. Example:

```diff
- [0.0000, 0.0000, 0.0000, 0.0000, 0.5300, 0.0000, 0.0000, 0.0000, 0.0000, 1.1221]
+            [
+                0.0000,
+                0.0000,
+                0.0000,
+                0.0000,
+                0.5300,
+                0.0000,
+                0.0000,
+                0.0000,
+                0.0000,
+                1.1221,
+            ]
```

Can you revert them? The PR is already huge like this so I'd like to keep it "as small as possible". 

Same for the 

```diff
- (f"encoder.deit.blocks.{i}.norm2.weight", f"encoder.encoder.layer.{i}.layernorm_after.weight")
+            (
+                f"encoder.deit.blocks.{i}.norm2.weight",
+                f"encoder.encoder.layer.{i}.layernorm_after.weight",
+            )
```

etc.

- Same comment for the pathlib updates

```diff
-    with open(filename, "w") as f:
-        f.write("\n".join(new_file_lines))
+      Path(filename).write_text("\n".join(new_file_lines))
```

While I agree with this codestyle,  I do think the changes should be made separately

> Currently there are only 6 instances where get_session is used - and they are all images hosted on HF. is this alright or revert these to httpx too?

Let's keep them as they are before this PR.

> Also, in src/transformers/safetensors_conversion.py, what should be used? Currently, httpx is used for this url - "https://safetensors-convert.hf.space"

`httpx` is good in this case

> There are a few docstrings where requests is used. Since the docs are user-facing, should i let this be as it is, or change it to httpx as well?

Let's change them to `httpx` as well.

Thanks in advance!

hey @Wauplin , i've reverted the formatting changes and updated the docstrings. I think it's good to go now. 
For some reason, the tests are failing. Could you tell me why, so that i can fix them...

Thanks!

failing test seems unrelated 

```
FAILED tests/models/udop/test_processing_udop.py::UdopProcessorTest::test_model_input_names - TypeError: TextInputSequence must be str
FAILED tests/models/udop/test_processing_udop.py::UdopProcessorTest::test_processor_with_multiple_inputs - TypeError: TextInputSequence must be str
============ 2 failed, 225 passed, 297 skipped in 108.35s (0:01:48) ============

Exited with code exit status 1
```

I cannot reproduce it locally :confused: 

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: aimv2, align, altclip, aria, beit, bit, blip, blip_2, bridgetower, chameleon, chinese_clip, clip, clipseg

> Thanks for this last iteration @omkar-334! I've made a few changes to fix the last remaining issues and reviewed all files manually. Took some time but definitely a good thing to clean up!

Thanks for the careful review and cleanup! @Wauplin .... my auto-format-on-save and search-and-replace on VS Code messed up things, but looks good in the end!


Thanks for your work! I'll be shipped as part of the v5 release (coming very soon)