PhotoMaker
PhotoMaker copied to clipboard
Problem running Gradio demo
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
I wonder what's wrong :(
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.
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
Will try moving the folder...
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'
I had to install photomaker by "pip install photomaker"
to get past that error, but I still have error I just posted about 🤔
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)
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'
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
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.
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!
Allmost worked...
-
Change line 42 in
venv\Lib\site-packages\spaces\zero\wrappers.py
fromProcess = multiprocessing.get_context('fork').Process
toProcess = multiprocessing.get_context('spawn').Process
-
move the files in
photomaker-dir
togradio_demo
-
remove original photomaker-dir
-
Change line 22 in pipeline.py from
from photomaker.model import PhotoMakerIDEncoder
tofrom model import PhotoMakerIDEncoder
-
Change line 14 in app.py from
from photomaker.pipeline import PhotoMakerStableDiffusionXLPipeline
tofrom pipeline import PhotoMakerStableDiffusionXLPipeline
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 :)
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 :)
yes, bad entry in readme - shoudl state required python 3.9 - this Tulpe error been the last error - now onto the stylized version :D
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)
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
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.
@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?
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
and put the style file in the root too
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.