lllyasviel / Fooocus

Focus on prompting and generating
GNU General Public License v3.0
38.19k stars 5.11k forks source link

[Bug]: Error in API; "AttributeError: 'dict' object has no attribute 'replace'" #3233

Closed zion4343 closed 1 week ago

zion4343 commented 1 week ago

Checklist

What happened?

Can anyone give me the example of using API? Although I tried to use the API, my program cause the error, "AttributeError: 'dict' object has no attribute 'replace'" I will post my program and the detail of the error.

Please let me know how can I solve the error.

Steps to reproduce the problem

from gradio_client import Client

import matplotlib.pyplot as plt import matplotlib.image as mpimg

client = Client("https://767cb031c1d6b9ee18.gradio.live/") #url of the working Fooocus result = client.predict( True, # bool in 'Generate Image Grid for Each Batch' Checkbox component "", # str in 'parameter_11' Textbox component "", # str in 'Negative Prompt' Textbox component ["Fooocus V2"], # List[str] in 'Selected Styles' Checkboxgroup component

#Performance
        "Hyper-SD", # str in 'Performance' Radio component

#Output ImageSize
        "1152×896 ∣ 9:7",   # str in 'Aspect Ratios' Radio component

#The Number of Images
        1,  # int | float (numeric value between 1 and 32) in 'Image Number' Slider component

#Image File Extension
        "png",  # str in 'Output Format' Radio component

        "", # str in 'Seed' Textbox component
        True,   # bool in 'Read wildcards in order' Checkbox component

#
#Advanced Setting
#
        2,  # int | float (numeric value between 0.0 and 30.0) in 'Image Sharpness' Slider component
        4,  # int | float (numeric value between 1.0 and 30.0) in 'Guidance Scale' Slider component

#BaseModel
        "juggernautXL_v8Rundiffusion.safetensors",  # str (Option from: []) in 'Base Model (SDXL only)' Dropdown component

#Refiner
        "None", # str (Option from: ['None']) in 'Refiner (SDXL or SD 1.5)' Dropdown component
        0.1,    # int | float (numeric value between 0.1 and 1.0) in 'Refiner Switch At' Slider component

#LoRA
        True,   # bool in 'Enable' Checkbox component
        "sd_xl_offset_example-lora_1.0.safetensors",    # str (Option from: ['None']) in 'LoRA 1' Dropdown component
        0.1,    # int | float (numeric value between -2 and 2) in 'Weight' Slider component

        True,   # bool in 'Enable' Checkbox component
        "None", # str (Option from: ['None']) in 'LoRA 2' Dropdown component
        1,  # int | float (numeric value between -2 and 2) in 'Weight' Slider component

        True,   # bool in 'Enable' Checkbox component
        "None", # str (Option from: ['None']) in 'LoRA 3' Dropdown component
        1,  # int | float (numeric value between -2 and 2) in 'Weight' Slider component

        True,   # bool in 'Enable' Checkbox component
        "None", # str (Option from: ['None']) in 'LoRA 4' Dropdown component
        1,  # int | float (numeric value between -2 and 2) in 'Weight' Slider component

        True,   # bool in 'Enable' Checkbox component
        "None", # str (Option from: ['None']) in 'LoRA 5' Dropdown component
        1,  # int | float (numeric value between -2 and 2) in 'Weight' Slider component

#
#Input Image
#
        True,   # bool in 'Input Image' Checkbox component
        "", # str in 'parameter_95' Textbox component

#
#Upscale or Variation
#
        "Disabled", # str in 'Upscale or Variation:' Radio component
        "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath or URL to image) in 'Image' Image component
        ["Left"],   # List[str] in 'Outpaint Direction' Checkboxgroup component

#
#Inpaint and Outpaint
#
#The images have to be in the folder of the Fooocus
        "/content/drive/MyDrive/Images/Target.jpg", # str (filepath or URL to image) in 'Image' Image component
        "", # str in 'Inpaint Additional Prompt' Textbox component
        "/content/drive/MyDrive/Images/MaskData/TargetHead.webp",   # str (filepath or URL to image) in 'Mask Upload' Image component

#
#Advanced Setting - Developer Debag Mode - Debag Tool
#
        True,   # bool in 'Disable Preview' Checkbox component
        True,   # bool in 'Disable Intermediate Results' Checkbox component
        False,  # bool in 'Disable seed increment' Checkbox component
        False,  # bool in 'Black Out NSFW' Checkbox component

        1.5,    # int | float (numeric value between 0.1 and 3.0) in 'Positive ADM Guidance Scaler' Slider component
        0.8,    # int | float (numeric value between 0.1 and 3.0) in 'Negative ADM Guidance Scaler' Slider component
        0.3,    # int | float (numeric value between 0.0 and 1.0) in 'ADM Guidance End At Step' Slider component
        7,  # int | float (numeric value between 1.0 and 30.0) in 'CFG Mimicking from TSNR' Slider component
        2,  # int | float (numeric value between 1 and 12) in 'CLIP Skip' Slider component

        "dpmpp_2m_sde_gpu", # str (Option from: ['euler', 'euler_ancestral', 'heun', 'heunpp2', 'dpm_2', 'dpm_2_ancestral', 'lms', 'dpm_fast', 'dpm_adaptive', 'dpmpp_2s_ancestral', 'dpmpp_sde', 'dpmpp_sde_gpu', 'dpmpp_2m', 'dpmpp_2m_sde', 'dpmpp_2m_sde_gpu', 'dpmpp_3m_sde', 'dpmpp_3m_sde_gpu', 'ddpm', 'lcm', 'tcd', 'ddim', 'uni_pc', 'uni_pc_bh2']) in 'Sampler' Dropdown component
        "karras",   # str (Option from: ['normal', 'karras', 'exponential', 'sgm_uniform', 'simple', 'ddim_uniform', 'lcm', 'turbo', 'align_your_steps', 'tcd', 'edm_playground_v2.5']) in 'Scheduler' Dropdown component
        "Default (model)",  # str (Option from: ['Default (model)']) in 'VAE' Dropdown component

        -1, # int | float (numeric value between -1 and 200) in 'Forced Overwrite of Sampling Step' Slider component
        -1, # int | float (numeric value between -1 and 200) in 'Forced Overwrite of Refiner Switch Step' Slider component
        -1, # int | float (numeric value between -1 and 2048) in 'Forced Overwrite of Generating Width' Slider component
        -1, # int | float (numeric value between -1 and 2048) in 'Forced Overwrite of Generating Height' Slider component
        -1, # int | float (numeric value between -1 and 1.0) in 'Forced Overwrite of Denoising Strength of "Vary"' Slider component
        -1, # int | float (numeric value between -1 and 1.0) in 'Forced Overwrite of Denoising Strength of "Upscale"' Slider component

#
#Advanced Setting - Developer Debag Mode - Control
#
        False,  # bool in 'Mixing Image Prompt and Vary/Upscale' Checkbox component
        True,   # bool in 'Mixing Image Prompt and Inpaint' Checkbox component
        False,  # bool in 'Debug Preprocessors' Checkbox component
        False,  # bool in 'Skip Preprocessors' Checkbox component

        64, # int | float (numeric value between 1 and 255) in 'Canny Low Threshold' Slider component
        128,    # int | float (numeric value between 1 and 255) in 'Canny High Threshold' Slider component
        "joint",    # str (Option from: ['joint', 'separate', 'vae']) #Debag Tool in 'Refiner swap method' Dropdown component
        0.25,   # int | float (numeric value between 0.0 and 1.0) in 'Softness of ControlNet' Slider component

#
#Advanced Setting - Developer Debag Mode - FreeU
#
        False,  # bool in 'Enabled' Checkbox component
        0,  # int | float (numeric value between 0 and 2) in 'B1' Slider component
        0,  # int | float (numeric value between 0 and 2) in 'B2' Slider component
        0,  # int | float (numeric value between 0 and 4) in 'S1' Slider component
        0,  # int | float (numeric value between 0 and 4) in 'S2' Slider component

#
#Advanced Setting - Developer Debag Mode - Inpaint
#
        False,  # bool in 'Debug Inpaint Preprocessing' Checkbox component
        False,  # bool in 'Disable initial latent in inpaint' Checkbox component

        "v2.6", # str (Option from: ['None', 'v1', 'v2.5', 'v2.6']) in 'Inpaint Engine' Dropdown component
        1,  # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Denoising Strength' Slider component
        0.618,  # int | float (numeric value between 0.0 and 1.0) in 'Inpaint Respective Field' Slider component

        False,  # bool in 'Enable Mask Upload' Checkbox component
        False,  # bool in 'Invert Mask' Checkbox component

        6,  # int | float (numeric value between -64 and 64) in 'Mask Erode or Dilate' Slider component

        False,  # bool in 'Save Metadata to Images' Checkbox component #Debag Tool
        "fooocus",  # str in 'Metadata Scheme' Radio component

#
#Image Prompt
#
#Image Prompt 1
        "/content/drive/MyDrive/Images/MaskData/TargetHead.webp",   # str (filepath or URL to image) in 'Image' Image component
        0.9,    # int | float (numeric value between 0.0 and 1.0) in 'Stop At' Slider component
        0.75,   # int | float (numeric value between 0.0 and 2.0) in 'Weight' Slider component
        "FaceSwap", # str in 'Type' Radio component

#Image Prompt 2
        "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath or URL to image) in 'Image' Image component
        0,  # int | float (numeric value between 0.0 and 1.0) in 'Stop At' Slider component
        0,  # int | float (numeric value between 0.0 and 2.0) in 'Weight' Slider component
        "ImagePrompt",  # str in 'Type' Radio component

#Image Prompt 3
        "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath or URL to image) in 'Image' Image component
        0,  # int | float (numeric value between 0.0 and 1.0) in 'Stop At' Slider component
        0,  # int | float (numeric value between 0.0 and 2.0) in 'Weight' Slider component
        "ImagePrompt",  # str in 'Type' Radio component

#Image Prompt 4
        "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath or URL to image) in 'Image' Image component
        0,  # int | float (numeric value between 0.0 and 1.0) in 'Stop At' Slider component
        0,  # int | float (numeric value between 0.0 and 2.0) in 'Weight' Slider component
        "ImagePrompt",  # str in 'Type' Radio component

        fn_index=46

)

result = client.predict( fn_index=47 )

img = mpimg.imread(result[2]) imgplot = plt.imshow(img) plt.show()

What should have happened?

Fooocus should not happen the error type.

What browsers do you use to access Fooocus?

Google Chrome

Where are you running Fooocus?

Cloud (Google Colab)

What operating system are you using?

No response

Console logs

Loaded as API: https://767cb031c1d6b9ee18.gradio.live/ ✔
AttributeError Traceback (most recent call last)
in <cell line: 178>()
176 )
177
--> 178 result = client.predict(
179 fn_index=47
180 )

12 frames
[/usr/local/lib/python3.10/dist-packages/gradio_client/client.py](https://localhost:8080/#) in predict(self, api_name, fn_index, *args, **kwargs)
461 return self.submit(
462 *args, api_name=api_name, fn_index=fn_index, **kwargs
--> 463 ).result()
464
465 def new_helper(self, fn_index: int) -> Communicator:

[/usr/local/lib/python3.10/dist-packages/gradio_client/client.py](https://localhost:8080/#) in result(self, timeout)
1483 >> 9
1484 """
-> 1485 return super().result(timeout=timeout)
1486
1487 def outputs(self) -> list[tuple | Any]:

[/usr/lib/python3.10/concurrent/futures/_base.py](https://localhost:8080/#) in result(self, timeout)
456 raise CancelledError()
457 elif self._state == FINISHED:
--> 458 return self.__get_result()
459 else:
460 raise TimeoutError()

[/usr/lib/python3.10/concurrent/futures/_base.py](https://localhost:8080/#) in __get_result(self)
401 if self._exception:
402 try:
--> 403 raise self._exception
404 finally:
405 # Break a reference cycle with the exception in self._exception

[/usr/lib/python3.10/concurrent/futures/thread.py](https://localhost:8080/#) in run(self)
56
57 try:
---> 58 result = self.fn(*self.args, **self.kwargs)
59 except BaseException as exc:
60 self.future.set_exception(exc)

[/usr/local/lib/python3.10/dist-packages/gradio_client/compatibility.py](https://localhost:8080/#) in _inner(*data)
64 data = self.serialize(*data)
65 predictions = _predict(*data)
---> 66 predictions = self.process_predictions(*predictions)
67 # Append final output only if not already present
68 # for consistency between generators and not generators

[/usr/local/lib/python3.10/dist-packages/gradio_client/compatibility.py](https://localhost:8080/#) in process_predictions(self, *predictions)
264 def process_predictions(self, *predictions):
265 if self.client.download_files:
--> 266 predictions = self.deserialize(*predictions)
267 predictions = self.remove_skipped_components(*predictions)
268 predictions = self.reduce_singleton_output(*predictions)

[/usr/local/lib/python3.10/dist-packages/gradio_client/compatibility.py](https://localhost:8080/#) in deserialize(self, *data)
250 )
251 outputs = tuple(
--> 252 [
253 s.deserialize(
254 d,

[/usr/local/lib/python3.10/dist-packages/gradio_client/compatibility.py](https://localhost:8080/#) in (.0)
251 outputs = tuple(
252 [
--> 253 s.deserialize(
254 d,
255 save_dir=self.client.output_dir,

[/usr/local/lib/python3.10/dist-packages/gradio_client/serializing.py](https://localhost:8080/#) in deserialize(self, x, save_dir, root_url, hf_token)
206 if x is None or x == "":
207 return None
--> 208 file = utils.decode_base64_to_file(x, dir=save_dir)
209 return file.name
210

[/usr/local/lib/python3.10/dist-packages/gradio_client/utils.py](https://localhost:8080/#) in decode_base64_to_file(encoding, file_path, dir, prefix)
763 directory = Path(dir or tempfile.gettempdir()) / secrets.token_hex(20)
764 directory.mkdir(exist_ok=True, parents=True)
--> 765 data, extension = decode_base64_to_binary(encoding)
766 if file_path is not None and prefix is None:
767 filename = Path(file_path).name

[/usr/local/lib/python3.10/dist-packages/gradio_client/utils.py](https://localhost:8080/#) in decode_base64_to_binary(encoding)
728
729 def decode_base64_to_binary(encoding: str) -> tuple[bytes, str | None]:
--> 730 extension = get_extension(encoding)
731 data = encoding.rsplit(",", 1)[-1]
732 return base64.b64decode(data), extension

[/usr/local/lib/python3.10/dist-packages/gradio_client/utils.py](https://localhost:8080/#) in get_extension(encoding)
674
675 def get_extension(encoding: str) -> str | None:
--> 676 encoding = encoding.replace("audio/wav", "audio/x-wav")
677 type = mimetypes.guess_type(encoding)[0]
678 if type == "audio/flac": # flac is not supported by mimetypes

AttributeError: 'dict' object has no attribute 'replace'

Additional information

No response

zion4343 commented 1 week ago

Although I see https://github.com/lllyasviel/Fooocus/issues/172 and tried to serialize, my program says

"TypeError Traceback (most recent call last) in <cell line: 6>() 4 import matplotlib.image as mpimg 5 ----> 6 client = Client("https://767cb031c1d6b9ee18.gradio.live/", serialize=False) #url of the working Fooocus 7 result = client.predict( 8 True, # bool in 'Generate Image Grid for Each Batch' Checkbox component

TypeError: Client.init() got an unexpected keyword argument 'serialize'

gradio_client already stoped to support serialization when gradio_client becomes v1.0 https://www.gradio.app/docs/python-client/version-1-release

zion4343 commented 1 week ago

3226

mashb1t commented 1 week ago

see https://github.com/lllyasviel/Fooocus/discussions/3226#discussioncomment-9954998