Formats a user-agent string with basic info about a request.
(user_agent: dict | str | None = None)
| 72 | |
| 73 | |
| 74 | def http_user_agent(user_agent: dict | str | None = None) -> str: |
| 75 | """ |
| 76 | Formats a user-agent string with basic info about a request. |
| 77 | """ |
| 78 | ua = f"diffusers/{__version__}; python/{sys.version.split()[0]}; session_id/{SESSION_ID}" |
| 79 | if HF_HUB_DISABLE_TELEMETRY or HF_HUB_OFFLINE: |
| 80 | return ua + "; telemetry/off" |
| 81 | if is_torch_available(): |
| 82 | ua += f"; torch/{_torch_version}" |
| 83 | if is_flax_available(): |
| 84 | ua += f"; jax/{_jax_version}" |
| 85 | ua += f"; flax/{_flax_version}" |
| 86 | if is_onnx_available(): |
| 87 | ua += f"; onnxruntime/{_onnxruntime_version}" |
| 88 | # CI will set this value to True |
| 89 | if os.environ.get("DIFFUSERS_IS_CI", "").upper() in ENV_VARS_TRUE_VALUES: |
| 90 | ua += "; is_ci/true" |
| 91 | if isinstance(user_agent, dict): |
| 92 | ua += "; " + "; ".join(f"{k}/{v}" for k, v in user_agent.items()) |
| 93 | elif isinstance(user_agent, str): |
| 94 | ua += "; " + user_agent |
| 95 | return ua |
| 96 | |
| 97 | |
| 98 | def load_or_create_model_card( |
no test coverage detected
searching dependent graphs…