Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem running Gradio demo #22

Open
Kallamamran opened this issue Jan 16, 2024 · 19 comments
Open

Problem running Gradio demo #22

Kallamamran opened this issue Jan 16, 2024 · 19 comments

Comments

@Kallamamran
Copy link

I've cloned PhotoMaker and installed a venv of Python 3.8.
All requirements has installed ok with help of an earlier version of pytorch since I got this first:

(venv) Q:\PhotoMaker>pip install -r requirements.txt
Collecting torch==2.0.1
Downloading torch-2.0.1-cp38-cp38-win_amd64.whl (172.4 MB)
|████████████████████████████████| 172.4 MB 6.4 MB/s
Collecting torchvision==0.15.2
Downloading torchvision-0.15.2-cp38-cp38-win_amd64.whl (1.2 MB)
|████████████████████████████████| 1.2 MB 6.4 MB/s

ERROR: Could not find a version that satisfies the requirement pytorch-cuda==11.8 (from versions: none)
ERROR: No matching distribution found for pytorch-cuda==11.8

Using older version of torch at least the installation worked:

pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 --index-url https://download.pytorch.org/whl/cu118

Now I have this error trying to run the Gradio demo though:

(venv) Q:\PhotoMaker>python gradio_demo/app.py
Traceback (most recent call last):
File "gradio_demo/app.py", line 10, in
import spaces
File "Q:\PhotoMaker\venv\lib\site-packages\spaces_init_.py", line 10, in
from .zero.decorator import GPU
File "Q:\PhotoMaker\venv\lib\site-packages\spaces\zero\decorator.py", line 18, in
from .wrappers import regular_function_wrapper
File "Q:\PhotoMaker\venv\lib\site-packages\spaces\zero\wrappers.py", line 42, in
Process = multiprocessing.get_context('fork').Process
File "C:\Users\Kallamamran\AppData\Local\Programs\Python\Python38\lib\multiprocessing\context.py", line 239, in get_context
return super().get_context(method)
File "C:\Users\Kallamamran\AppData\Local\Programs\Python\Python38\lib\multiprocessing\context.py", line 193, in get_context
raise ValueError('cannot find context for %r' % method) from None
ValueError: cannot find context for 'fork'

I wonder what's wrong :(

@nitrosocke
Copy link

nitrosocke commented Jan 16, 2024

This seems to be an issue with spaces on windows. Somewhat related to this: Issue #129
I solved it by editing line 42 in venv\Lib\site-packages\spaces\zero\wrappers.py from:
Process = multiprocessing.get_context('fork').Process to
Process = multiprocessing.get_context('spawn').Process

Also needed to drag the photomaker directory containing the pipeline into the gradio_demo folder.
Not sure if this is the ideal solution but a workaround on windows.

@Kallamamran
Copy link
Author

Kallamamran commented Jan 16, 2024

I've done the fork -> spawn thing, but that still gives me an error

(venv) Q:\PhotoMaker>python gradio_demo/app.py
Traceback (most recent call last):
File "gradio_demo/app.py", line 17, in
from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline
ModuleNotFoundError: No module named 'photomaker.pipeline'

Will try moving the folder...

@NolenBrolen
Copy link

NolenBrolen commented Jan 16, 2024

Also changed the line of code from 'fork' to 'spawn' but I still get a similar ModuleNotFoundError
(venv-photomaker) C:\Users\USER\PhotoMaker>python gradio_demo/app.py Traceback (most recent call last): File "C:\Users\USER\PhotoMaker\gradio_demo\app.py", line 13, in <module> from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline ModuleNotFoundError: No module named 'photomaker'

@Kallamamran
Copy link
Author

Kallamamran commented Jan 16, 2024

I had to install photomaker by "pip install photomaker" to get past that error, but I still have error I just posted about 🤔

@tdslaine
Copy link

tdslaine commented Jan 16, 2024

I've done the fork -> spawn thing, but that still gives me an error

(venv) Q:\PhotoMaker>python gradio_demo/app.py Traceback (most recent call last): File "gradio_demo/app.py", line 17, in from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline ModuleNotFoundError: No module named 'photomaker.pipeline'

Will try moving the folder...

I had to put all files from photomaker folder into the root where app.py is located @, removing the subfolder photomaker completly and adjusting the app.py as well as the pipeline.py to not look inside photomaker. folder for the modules

so it looks like:

  • gradio_demo:

    app.py
    model.py
    pipeline.py
    sytle_template.py

I also had to change:

line 22 in pipeline.py
original: from photomaker.model import PhotoMakerIDEncoder
altered: from model import PhotoMakerIDEncoder

and
line 14 in app.py
original: from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline
altered: from pipeline import PhotoMakerStableDiffusionXLPipeline

EDIT: the issure with not finding the req files/modules in the subfolder might be caused by a missing init.py file inside that folder (can be an empty file)

@NolenBrolen
Copy link

NolenBrolen commented Jan 16, 2024

I had to install photomaker by "pip install photomaker" to get past that error, but I still have error I just posted about 🤔

This won't work cuz it's another library you're installing, which is used to make funny pictures https://pypi.org/project/photomaker/

I just tried the following:

  • in terminal type "Python" or "Python3"
  • then paste the code to download the models from huggingface: from huggingface_hub import hf_hub_download
    photomaker_path = hf_hub_download(repo_id="TencentARC/PhotoMaker", filename="photomaker-v1.bin", repo_type="model")
  • It's currently downloading so hope this fixes it

Edit: installing the models did not fix the ModuleNotFoundError: No Module named 'photomaker'

@tdslaine
Copy link

I had to install photomaker by "pip install photomaker" to get past that error, but I still have error I just posted about 🤔

This won't work cuz it's another library you're installing, which is used to make funny pictures https://pypi.org/project/photomaker/

I just tried the following:

* in terminal type "Python" or "Python3"

* then paste the code to download the models from huggingface: from huggingface_hub import hf_hub_download
  photomaker_path = hf_hub_download(repo_id="TencentARC/PhotoMaker", filename="photomaker-v1.bin", repo_type="model")

* It's currently downloading so hope this fixes it

Edit: installing the models did not fix the ModuleNotFoundError: No Module named 'photomaker'

try my solution -with all files into the gradient_demo folder, and adjusting the two .py files to not look into the photomaker studio as described above. it works for me until now - gotta wait for the download to finish

grafik

@Syndulla
Copy link

Let us know if you get reasonable outputs. I followed the approach above and got Gradio running, but my outputs are a blobby brown noise.

@NolenBrolen
Copy link

I've done the fork -> spawn thing, but that still gives me an error
(venv) Q:\PhotoMaker>python gradio_demo/app.py Traceback (most recent call last): File "gradio_demo/app.py", line 17, in from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline ModuleNotFoundError: No module named 'photomaker.pipeline'
Will try moving the folder...

I had to put all files from photomaker folder into the root where app.py is located @, removing the subfolder photomaker completly and adjusting the app.py as well as the pipeline.py to not look inside photomaker. folder for the modules

so it looks like:

  • gradio_demo:

    app.py
    model.py
    pipeline.py
    sytle_template.py

I also had to change:

line 22 in pipeline.py original: from photomaker.model import PhotoMakerIDEncoder altered: from model import PhotoMakerIDEncoder

and line 14 in app.py original: from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline altered: from pipeline import PhotoMakerStableDiffusionXLPipeline

This worked! Thank you so much!

@Kallamamran
Copy link
Author

Kallamamran commented Jan 16, 2024

Allmost worked...

  1. Change line 42 in venv\Lib\site-packages\spaces\zero\wrappers.py from Process = multiprocessing.get_context('fork').Process to Process = multiprocessing.get_context('spawn').Process

  2. move the files in photomaker-dir to gradio_demo

  3. remove original photomaker-dir

  4. Change line 22 in pipeline.py from from photomaker.model import PhotoMakerIDEncoder to from model import PhotoMakerIDEncoder

  5. Change line 14 in app.py from from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline to from pipeline import PhotoMakerStableDiffusionXLPipeline

image

@justinjohn0306
Copy link

justinjohn0306 commented Jan 16, 2024

Process = multiprocessing.get_context('fork').Process

Use python 3.10 or add these line in app.py :

add this line at the top ---> from typing import Tuple

find this line ---> def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:

and replace with this one ---> def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:

it works for me :)

image

@tdslaine
Copy link

Process = multiprocessing.get_context('fork').Process

Use python 3.10 or add these line in app.py :

add this line at the top ---> from typing import Tuple

find this line ---> def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:

and replace with this one ---> def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:

it works for me :)
image

yes, bad entry in readme - shoudl state required python 3.9 - this Tulpe error been the last error - now onto the stylized version :D

@xhoxye
Copy link

xhoxye commented Jan 17, 2024

E:\AI\Fooocus\PhotoMaker>.\python_embeded\python.exe -s PhotoMaker/app.py Traceback (most recent call last): File "E:\AI\Fooocus\PhotoMaker\PhotoMaker\app.py", line 10, in <module> import spaces File "E:\AI\Fooocus\PhotoMaker\python_embeded\lib\site-packages\spaces\__init__.py", line 10, in <module> from .zero.decorator import GPU File "E:\AI\Fooocus\PhotoMaker\python_embeded\lib\site-packages\spaces\zero\decorator.py", line 17, in <module> from . import client File "E:\AI\Fooocus\PhotoMaker\python_embeded\lib\site-packages\spaces\zero\client.py", line 17, in <module> from .gradio import get_event File "E:\AI\Fooocus\PhotoMaker\python_embeded\lib\site-packages\spaces\zero\gradio.py", line 8, in <module> from gradio.context import LocalContext ImportError: cannot import name 'LocalContext' from 'gradio.context' (E:\AI\Fooocus\PhotoMaker\python_embeded\lib\site-packages\gradio\context.py)
QQ截图20240117093636

@dancemanUK
Copy link

Built Distributions
photomaker-1.0.1-py3-none-any.whl (4.1 kB view hashes)
Uploaded Nov 18, 2022 py3

photomaker-1.0.1-1-py3-none-any.whl (3.1 MB view hashes)
Uploaded Nov 18, 2022 py3

wechat_20240117181712 wechat_20240117181733 wechat_20240117181806

@Paper99
Copy link
Collaborator

Paper99 commented Jan 17, 2024

Hello everyone, first of all, thank you for your discussions, which helped us fix many known issues in environment construction (in the latest version).

Now, you could update the environment building through:

conda create --name photomaker python=3.10
pip install -U pip

# Install requirements
pip install -r requirements.txt

# Install photomaker
pip install git+https://github.com/TencentARC/PhotoMaker.git

Then you can run the following command to use our PhotoMaker:

from photomaker import PhotoMakerStableDiffusionXLPipeline

The previous line can also be used outside the repo.

@xhoxye
Copy link

xhoxye commented Jan 17, 2024

@dancemanUK
Please ask, why I downloaded the file according to your screenshot, and there is no response after it can be run, why is this?

@seoeaa
Copy link

seoeaa commented Jan 18, 2024

Guys, you don’t need to be tricky, just put the file in the root and that’s it, change the extension to .py
app1.txt

@seoeaa
Copy link

seoeaa commented Jan 18, 2024

and put the style file in the root too

@sitzbrau
Copy link

Guys, you don’t need to be tricky, just put the file in the root and that’s it, change the extension to .py app1.txt

running on sagemaker i've got this

(photomaker) studio-lab-user@default:~/PhotoMaker$ python app1.py
Loading pipeline components...: 100%|███████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:40<00:00,  5.81s/it]
Loading PhotoMaker components [1] id_encoder from [/home/studio-lab-user/.cache/huggingface/hub/models--TencentARC--PhotoMaker/snapshots/3602d02ba7cc99ce8886e24063ed10e4f2510c84]...
Loading PhotoMaker components [2] lora_weights from [/home/studio-lab-user/.cache/huggingface/hub/models--TencentARC--PhotoMaker/snapshots/3602d02ba7cc99ce8886e24063ed10e4f2510c84]
Running on local URL:  http://127.0.0.1:7860
2024/02/19 18:15:34 [W] [service.go:132] login to server failed: dial tcp 44.237.78.176:7000: i/o timeout

Could not create share link. Please check your internet connection or our status page: https://status.gradio.app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests