Transformers
PyTorch
clip
anon-repair-bot commited on
Commit
176edb4
·
verified ·
1 Parent(s): cb41f3a

Fix: Invalid import of SafetyChecker in example code

Browse files

## Description

The example code in the model card fails with the following error:
```python
from transformers import AutoProcessor, SafetyChecker
# ImportError: cannot import name 'SafetyChecker' from 'transformers'
```

## Changes

Replaced:
```python
from transformers import AutoProcessor, SafetyChecker
```
with:
```python
from transformers import CLIPFeatureExtractor as AutoProcessor
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker as SafetyChecker
```

## Testing
The code has been successfully tested and runs without error.

## Note
This contribution is part of an ongoing research initiative to systematically identify and correct faulty example code in Hugging Face Model Cards.
We would appreciate a timely review and integration of this patch to support code reliability and enhance reproducibility for downstream users.

Files changed (1) hide show
  1. README.md +4 -1
README.md CHANGED
@@ -174,7 +174,10 @@ Use the code below to get started with the model.
174
  <summary> Click to expand </summary>
175
 
176
  ```python
177
- from transformers import AutoProcessor, SafetyChecker
 
 
 
178
  processor = AutoProcessor.from_pretrained("CompVis/stable-diffusion-safety-checker")
179
  safety_checker = SafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker")
180
  ```
 
174
  <summary> Click to expand </summary>
175
 
176
  ```python
177
+ #from transformers import AutoProcessor, SafetyChecker
178
+ from transformers import CLIPFeatureExtractor as AutoProcessor
179
+ from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker as SafetyChecker
180
+
181
  processor = AutoProcessor.from_pretrained("CompVis/stable-diffusion-safety-checker")
182
  safety_checker = SafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker")
183
  ```