mrhan1993 / Fooocus-API

FastAPI powered API for Fooocus
GNU General Public License v3.0
502 stars 131 forks source link

Generating NSFW compliant images #338

Closed DisantHoridnt closed 1 month ago

DisantHoridnt commented 1 month ago

Description:

Thank you for great job that you are doing with FooocusApi.

We are attempting to incorporate NSFW models into our API built from the repo-- Fooocus-API. We have added some new models to have the API generate NSFW compliant images. However, we are currently facing an issue where the app does not generate any images. Do you have any ideas on how to integrate nsfw into the repo?

Expected Behavior: The app should generate NSFW compliant images.

Actual Behavior: The models take an excessively long time to load and do not generate any images.

Attachments: Screen recording

Additional Context: We are using the following environment setup:

davefojtik commented 1 month ago

This sounds more like a problem with the specific model you're trying to use. Neither Fooocus nor Fooocus-API are censored and are generating NSFW images just fine. The screen recording you attached cannot be played, therefore more info about the model or what's happening is needed.

pribeh commented 1 month ago

Hi @davefojtik , thank you for your response. Let me see if I can clarify a few things. The issue is that it looks like new changes are coming to Fooocus library that appear to break Fooocus API requests from our initial tests. Let me provide some context

We're testing out a new feature that utilizes models that help to filter OUT NSFW content – that black them out – introduced in this pull request

https://github.com/lllyasviel/Fooocus/pull/958

The feature is available in the "develop" branch (here) and will be introduced into master soon I presume. We've tested this branch as well as @mashb1t's fork of Fooocus (here) and each time it breaks our text-to-image requests.

We brought it up with the maintainers of the Fooocus library (here) and they suggested we raise the issue here.

We did also set the NSFW config boolean to false and the request also produces an error. The only type of successful response we got was when making a ping pong request.

We can confirm that the Fooocus library is running

Steps to reproduce:

Result:

foocus-api          | [2024-05-24 04:47:29] INFO     [Task Queue] Waiting for task finished, job_id=a8767989-161e-4eb1-8a78-e2b8e699b14d
fooocus-api          | Exception in thread Thread-2 (task_schedule_loop):
fooocus-api          | Traceback (most recent call last):
fooocus-api          |   File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
fooocus-api          |     self.run()
fooocus-api          |   File "/usr/lib/python3.10/threading.py", line 953, in run
fooocus-api          |     self._target(*self._args, **self._kwargs)
fooocus-api          |   File "/opt/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
fooocus-api          |     return func(*args, **kwargs)
fooocus-api          |   File "/opt/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
fooocus-api          |     return func(*args, **kwargs)
fooocus-api          |   File "/app/fooocusapi/worker.py", line 47, in task_schedule_loop
fooocus-api          |     process_generate(current_task)
fooocus-api          |   File "/opt/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
fooocus-api          |     return func(*args, **kwargs)
fooocus-api          |   File "/opt/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
fooocus-api          |     return func(*args, **kwargs)
fooocus-api          |   File "/app/fooocusapi/worker.py", line 94, in process_generate
fooocus-api          |     from modules.sdxl_styles import apply_style, fooocus_expansion, apply_wildcards
fooocus-api          | ImportError: cannot import name 'apply_wildcards' from 'modules.sdxl_styles' (/app/repositories/Fooocus/modules/sdxl_styles.py)
mashb1t commented 1 month ago

@pribeh the error message hints at apply_wildcards not being in modules.sdxl_styles, but both Fooocus and Fooocus-API have the method there. Is it possible that this method has been deleted by accident in your code?

davefojtik commented 1 month ago

Replace the 9 files/folders in repositories/fooocus with the contents of the develop Fooocus branch

You can't just replace the supported Fooocus with a different fork, newer version or in this case even a dev branch and expect it to work flawlessly. The API is written for a specific version for a reason. I suggest waiting for it to be released both in Fooocus and then in Fooocus-API or helping to add it via pull request so it can be added in the next compatibility update.

mrhan1993 commented 1 month ago

@PrinceDisant @pribeh I pushed dev branch that support to Fooocus Dev branch

After the preliminary test, nsfw checker is work well. If you want to block nsfw result, set black_out_nsfw to true in advanced_params, it will return a black image if result is nsfw.

you can do more test, if any questions, reply here

DisantHoridnt commented 1 month ago

It actually worked! I was able to integrate, I was missing the advanced params integration. Thank you so much @mrhan1993 and @mashb1t for this. Our users would not be able to use our app safely. Please check out our platform here: https://rebl.ai/