lllyasviel / Fooocus

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

[BUG] Cannot use gradio api to generate images. #555

Closed pieceof closed 9 months ago

pieceof commented 1 year ago

The client code as follow(my fooocus server is startted at port 8860):

from gradio_client import Client

client = Client("http://127.0.0.1:8860/", serialize=False)
result = client.predict(
                "Howdy!",   # str in 'parameter_8' Textbox component
                "Howdy!",   # str in 'Negative Prompt' Textbox component
                "Fooocus V2",   # List[str] in 'Image Style' Checkboxgroup component
                "Speed",    # str in 'Performance' Radio component
                "704×1408", # str in 'Aspect Ratios' Radio component
                1,  # int | float (numeric value between 1 and 32) in 'Image Number' Slider component
                5,  # int | float in 'Seed' Number component
                0,  # int | float (numeric value between 0.0 and 30.0) in 'Sampling Sharpness' Slider component
                "sd_xl_refiner_1.0_0.9vae.safetensors", # str (Option from: ['sd_xl_refiner_1.0_0.9vae.safetensors', 'sdxlUnstableDiffusers_v6StabilityEater.safetensors', 'r2D2Diffusion_v10.safetensors', 'sd_xl_refiner_1.0.safetensors', 'majicmixReverie_v10.safetensors', 'sdxlYamersAnimeUltra_yamersAnimeV3.safetensors', 'majicmixRealistic_v6.safetensors', 'dreamshaperXL10_alpha2Xl10.safetensors', 'Aidv210AnimeIllustDiffusion_aidv210.safetensors', 'sdxl10ArienmixxlAsian_v20.safetensors', 'anyloraCheckpoint_bakedvaeBlessedFp16.safetensors', 'sd_xl_base_1.0_0.9vae.safetensors', 'SDXLRonghua_v20.safetensors', 'realisticVisionV51_v51VAE.safetensors', 'sd_xl_base_1.0.safetensors', 'sdxlYamersRealism_version2.safetensors']) in 'SDXL Base Model' Dropdown component
                "None", # str (Option from: ['None', 'sd_xl_refiner_1.0_0.9vae.safetensors', 'sdxlUnstableDiffusers_v6StabilityEater.safetensors', 'r2D2Diffusion_v10.safetensors', 'sd_xl_refiner_1.0.safetensors', 'majicmixReverie_v10.safetensors', 'sdxlYamersAnimeUltra_yamersAnimeV3.safetensors', 'majicmixRealistic_v6.safetensors', 'dreamshaperXL10_alpha2Xl10.safetensors', 'Aidv210AnimeIllustDiffusion_aidv210.safetensors', 'sdxl10ArienmixxlAsian_v20.safetensors', 'anyloraCheckpoint_bakedvaeBlessedFp16.safetensors', 'sd_xl_base_1.0_0.9vae.safetensors', 'SDXLRonghua_v20.safetensors', 'realisticVisionV51_v51VAE.safetensors', 'sd_xl_base_1.0.safetensors', 'sdxlYamersRealism_version2.safetensors']) in 'SDXL Refiner' Dropdown component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 1' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 2' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 3' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 4' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 5' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                True,   # bool in 'Input Image' Checkbox component
                "Howdy!",   # str in 'parameter_30' Textbox component
                "Disabled", # str in 'Upscale or Variation:' Radio component
                "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath on your computer (or URL) of image) in 'Drag above image to here' Image component
                "Left", # List[str] in 'Outpaint' Checkboxgroup component
                "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath on your computer (or URL) of image) in 'Drag above image to here' Image component
                fn_index=13
)
print(result)

The error message as follows:

Traceback (most recent call last):
  File "/home/barricade/code/sd/proxy_fooocus/main.py", line 5, in <module>
    result = client.predict(
  File "/home/barricade/.conda/envs/proxy-fooocus/lib/python3.10/site-packages/gradio_client/client.py", line 291, in predict
    return self.submit(*args, api_name=api_name, fn_index=fn_index).result()
  File "/home/barricade/.conda/envs/proxy-fooocus/lib/python3.10/site-packages/gradio_client/client.py", line 1120, in result
    return super().result(timeout=timeout)
  File "/home/barricade/.conda/envs/proxy-fooocus/lib/python3.10/concurrent/futures/_base.py", line 458, in result
    return self.__get_result()
  File "/home/barricade/.conda/envs/proxy-fooocus/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/home/barricade/.conda/envs/proxy-fooocus/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/barricade/.conda/envs/proxy-fooocus/lib/python3.10/site-packages/gradio_client/client.py", line 793, in _inner
    predictions = _predict(*data)
  File "/home/barricade/.conda/envs/proxy-fooocus/lib/python3.10/site-packages/gradio_client/client.py", line 824, in _predict
    raise ValueError(result["error"])
ValueError: None

The error in fooocus server as follows:

Traceback (most recent call last):
  File "/home/barricade/.conda/envs/fooocus/lib/python3.10/site-packages/gradio/routes.py", line 442, in run_predict
    output = await app.get_blocks().process_api(
  File "/home/barricade/.conda/envs/fooocus/lib/python3.10/site-packages/gradio/blocks.py", line 1390, in process_api
    inputs = self.preprocess_data(fn_index, inputs, state)
  File "/home/barricade/.conda/envs/fooocus/lib/python3.10/site-packages/gradio/blocks.py", line 1233, in preprocess_data
    processed_input.append(block.preprocess(inputs[i]))
  File "/home/barricade/code/sd/Fooocus/modules/gradio_hijack.py", line 275, in preprocess
    im = processing_utils.decode_base64_to_image(x)
  File "/home/barricade/.conda/envs/fooocus/lib/python3.10/site-packages/gradio/processing_utils.py", line 59, in decode_base64_to_image
    img = Image.open(BytesIO(base64.b64decode(image_encoded)))
  File "/home/barricade/.conda/envs/fooocus/lib/python3.10/base64.py", line 87, in b64decode
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

My native language is not English, please try to understand. If anything is unclear, please ask again.

pieceof commented 1 year ago

I pulled from the repository again and updated the code as follows:

from gradio_client import Client

client = Client("http://localhost:8860/", serialize=False)
result = client.predict(
                "Howdy!",   # str in 'parameter_8' Textbox component
                "Howdy!",   # str in 'Negative Prompt' Textbox component
                "Fooocus V2",   # List[str] in 'Image Style' Checkboxgroup component
                "Speed",    # str in 'Performance' Radio component
                "704×1408", # str in 'Aspect Ratios' Radio component
                1,  # int | float (numeric value between 1 and 32) in 'Image Number' Slider component
                5,  # int | float in 'Seed' Number component
                0,  # int | float (numeric value between 0.0 and 30.0) in 'Sampling Sharpness' Slider component
                0.1,    # int | float (numeric value between 0.1 and 3.0) in 'Positive ADM Guidance Scaler' Slider component
                0.1,    # int | float (numeric value between 0.1 and 3.0) in 'Negative ADM Guidance Scaler' Slider component
                0,  # int | float (numeric value between 0.0 and 1.0) in 'ADM Guidance End At Step' Slider component
                1,  # int | float (numeric value between 1.0 and 30.0) in 'Guidance Scale' Slider component
                1,  # int | float (numeric value between 1.0 and 30.0) in 'CFG Mimicking from TSNR' Slider component
                "euler",    # str (Option from: ['euler', 'euler_ancestral', 'heun', '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', 'uni_pc', 'uni_pc_bh2']) in 'Sampler' Dropdown component
                "normal",   # str (Option from: ['normal', 'karras', 'exponential', 'sgm_uniform', 'simple', 'ddim_uniform']) in 'Scheduler' 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
                "sd_xl_refiner_1.0_0.9vae.safetensors", # str (Option from: ['sd_xl_refiner_1.0_0.9vae.safetensors', 'sdxlUnstableDiffusers_v6StabilityEater.safetensors', 'r2D2Diffusion_v10.safetensors', 'sd_xl_refiner_1.0.safetensors', 'majicmixReverie_v10.safetensors', 'sdxlYamersAnimeUltra_yamersAnimeV3.safetensors', 'majicmixRealistic_v6.safetensors', 'dreamshaperXL10_alpha2Xl10.safetensors', 'Aidv210AnimeIllustDiffusion_aidv210.safetensors', 'sdxl10ArienmixxlAsian_v20.safetensors', 'anyloraCheckpoint_bakedvaeBlessedFp16.safetensors', 'sd_xl_base_1.0_0.9vae.safetensors', 'SDXLRonghua_v20.safetensors', 'realisticVisionV51_v51VAE.safetensors', 'sd_xl_base_1.0.safetensors', 'sdxlYamersRealism_version2.safetensors']) in 'SDXL Base Model' Dropdown component
                "None", # str (Option from: ['None', 'sd_xl_refiner_1.0_0.9vae.safetensors', 'sdxlUnstableDiffusers_v6StabilityEater.safetensors', 'r2D2Diffusion_v10.safetensors', 'sd_xl_refiner_1.0.safetensors', 'majicmixReverie_v10.safetensors', 'sdxlYamersAnimeUltra_yamersAnimeV3.safetensors', 'majicmixRealistic_v6.safetensors', 'dreamshaperXL10_alpha2Xl10.safetensors', 'Aidv210AnimeIllustDiffusion_aidv210.safetensors', 'sdxl10ArienmixxlAsian_v20.safetensors', 'anyloraCheckpoint_bakedvaeBlessedFp16.safetensors', 'sd_xl_base_1.0_0.9vae.safetensors', 'SDXLRonghua_v20.safetensors', 'realisticVisionV51_v51VAE.safetensors', 'sd_xl_base_1.0.safetensors', 'sdxlYamersRealism_version2.safetensors']) in 'SDXL Refiner' Dropdown component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 1' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 2' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 3' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 4' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                "None", # str (Option from: ['None', 'CyberPunkAI.safetensors', 'sd_xl_offset_example-lora_1.0.safetensors', '国风插画SDXL.safetensors', 'more_details.safetensors', 'lego_v2.0.safetensors', 'genshinfull1-000006.safetensors', 'zelda.safetensors']) in 'SDXL LoRA 5' Dropdown component
                -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component
                True,   # bool in 'Input Image' Checkbox component
                "Howdy!",   # str in 'parameter_30' Textbox component
                "Disabled", # str in 'Upscale or Variation:' Radio component
                "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath on your computer (or URL) of image) in 'Drag above image to here' Image component
                "Left", # List[str] in 'Outpaint' Checkboxgroup component
                "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath on your computer (or URL) of image) in 'Drag above image to here' Image component
                fn_index=14
)
print(result)

The wrong message have not changed

zhuojg commented 1 year ago

according to gradio docs, when set serialize to False, you should submit image using base64 format.

If set to False, the client will pass the inputs and outputs as-is, without serializing/deserializing them. E.g. you if you set this to False, you'd submit an image in base64 format instead of a filepath, and you'd get back an image in base64 format from the remote API instead of a filepath.

So you can use something like data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg== to replace image urls.

xplfly commented 1 year ago

change some param , for example

True, # bool in 'Input Image' Checkbox component--------set False

why process the image? job = client.submit( prompt, # str in 'parameter_8' Textbox component negative_prompt, # str in 'Negative Prompt' Textbox component ['Fooocus V2'], # List[str] in 'Image Style' Checkboxgroup component performance, # str in 'Performance' Radio component "{}×{}".format(width, height), # str in 'Aspect Ratios' Radio component 1, # int | float (numeric value between 1 and 32) in 'Image Number' Slider component max_seed, # int | float in 'Seed' Number component 0, # int | float (numeric value between 0.0 and 30.0) in 'Sampling Sharpness' Slider component 1, # int | float (numeric value between 1.0 and 30.0) in 'Guidance Scale' Slider component "sd_xl_base_1.0_0.9vae.safetensors", # str (Option from: ['sd_xl_refiner_1.0_0.9vae.safetensors', 'sd_xl_base_1.0_0.9vae.safetensors']) in 'SDXL Base Model' Dropdown component "sd_xl_refiner_1.0_0.9vae.safetensors", # str (Option from: ['None', 'sd_xl_refiner_1.0_0.9vae.safetensors', 'sd_xl_base_1.0_0.9vae.safetensors']) in 'SDXL Refiner' Dropdown component "None", # str (Option from: ['None']) in 'SDXL LoRA 1' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component "None", # str (Option from: ['None']) in 'SDXL LoRA 2' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component "None", # str (Option from: ['None']) in 'SDXL LoRA 3' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component "None", # str (Option from: ['None']) in 'SDXL LoRA 4' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component "None", # str (Option from: ['None']) in 'SDXL LoRA 5' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component False, # bool in 'Input Image' Checkbox component "", # str in 'parameter_66' Textbox component "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 'Drag above image to here' Image component "Left", # List[str] in 'Outpaint' Checkboxgroup component "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath or URL to image) in 'Drag above image to here' Image component "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 "Image Prompt", # str in 'Type' 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 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 "Image Prompt", # str in 'Type' 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 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 "Image Prompt", # str in 'Type' 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 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 "Image Prompt", # str in 'Type' Radio component fn_index=22 )

errro meesage : Traceback (most recent call last): File "/root/xl/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/routes.py", line 442, in run_predict output = await app.get_blocks().process_api( File "/root/xl/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1390, in process_api inputs = self.preprocess_data(fn_index, inputs, state) File "/root/xl/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1233, in preprocess_data processed_input.append(block.preprocess(inputs[i])) File "/root/Fooocus2/Fooocus/modules/gradio_hijack.py", line 275, in preprocess im = processing_utils.decode_base64_to_image(x) File "/root/xl/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/processing_utils.py", line 59, in decode_base64_to_image img = Image.open(BytesIO(base64.b64decode(image_encoded))) File "/root/anaconda3/envs/fooocus/lib/python3.10/base64.py", line 87, in b64decode return binascii.a2b_base64(s)

zhuojg commented 1 year ago

change some param , for example

True, # bool in 'Input Image' Checkbox component--------set False

why process the image? job = client.submit( prompt, # str in 'parameter_8' Textbox component negative_prompt, # str in 'Negative Prompt' Textbox component ['Fooocus V2'], # List[str] in 'Image Style' Checkboxgroup component performance, # str in 'Performance' Radio component "{}×{}".format(width, height), # str in 'Aspect Ratios' Radio component 1, # int | float (numeric value between 1 and 32) in 'Image Number' Slider component max_seed, # int | float in 'Seed' Number component 0, # int | float (numeric value between 0.0 and 30.0) in 'Sampling Sharpness' Slider component 1, # int | float (numeric value between 1.0 and 30.0) in 'Guidance Scale' Slider component "sd_xl_base_1.0_0.9vae.safetensors", # str (Option from: ['sd_xl_refiner_1.0_0.9vae.safetensors', 'sd_xl_base_1.0_0.9vae.safetensors']) in 'SDXL Base Model' Dropdown component "sd_xl_refiner_1.0_0.9vae.safetensors", # str (Option from: ['None', 'sd_xl_refiner_1.0_0.9vae.safetensors', 'sd_xl_base_1.0_0.9vae.safetensors']) in 'SDXL Refiner' Dropdown component "None", # str (Option from: ['None']) in 'SDXL LoRA 1' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component "None", # str (Option from: ['None']) in 'SDXL LoRA 2' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component "None", # str (Option from: ['None']) in 'SDXL LoRA 3' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component "None", # str (Option from: ['None']) in 'SDXL LoRA 4' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component "None", # str (Option from: ['None']) in 'SDXL LoRA 5' Dropdown component -2, # int | float (numeric value between -2 and 2) in 'Weight' Slider component False, # bool in 'Input Image' Checkbox component "", # str in 'parameter_66' Textbox component "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 'Drag above image to here' Image component "Left", # List[str] in 'Outpaint' Checkboxgroup component "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # str (filepath or URL to image) in 'Drag above image to here' Image component "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 "Image Prompt", # str in 'Type' 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 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 "Image Prompt", # str in 'Type' 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 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 "Image Prompt", # str in 'Type' 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 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 "Image Prompt", # str in 'Type' Radio component fn_index=22 )

errro meesage : Traceback (most recent call last): File "/root/xl/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/routes.py", line 442, in run_predict output = await app.get_blocks().process_api( File "/root/xl/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1390, in process_api inputs = self.preprocess_data(fn_index, inputs, state) File "/root/xl/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1233, in preprocess_data processed_input.append(block.preprocess(inputs[i])) File "/root/Fooocus2/Fooocus/modules/gradio_hijack.py", line 275, in preprocess im = processing_utils.decode_base64_to_image(x) File "/root/xl/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/processing_utils.py", line 59, in decode_base64_to_image img = Image.open(BytesIO(base64.b64decode(image_encoded))) File "/root/anaconda3/envs/fooocus/lib/python3.10/base64.py", line 87, in b64decode return binascii.a2b_base64(s)

I think gradio doesn't know which parameters will be used, so it have to process all input properly.

konieshadow commented 1 year ago

I made a replicate model for Fooocus, and a project which export http apis from Fooocus. Please check https://replicate.com/konieshadow/fooocus-api and https://github.com/konieshadow/Fooocus-API.

The http api is power by fastapi and very well documented.

Novosti1 commented 10 months ago

Yes, same story here i cant use API. it's not working.

DevepNoName commented 10 months ago
from gradio_client import Client

client = Client("http://127.0.0.1:7865/", serialize=False)
result = client.predict(
    "Howdy!",   # str in 'parameter_10' Textbox component
    "Howdy!",   # str in 'Negative Prompt' Textbox component
    ["Fooocus V2"], # List[str] in 'Selected Styles' Checkboxgroup component
    "Speed",    # str in 'Performance' Radio component
    "1152×896", # <span style='color: grey;'> | 1:2</span>",    # str in 'Aspect Ratios' Radio component
    1,  # int | float (numeric value between 1 and 32)in 'Image Number' Slider component
    "123",  # str in 'Seed' Textbox component
    0,  # int | float (numeric value between 0.0 and 30.0)in 'Image Sharpness' Slider component
    1,  # int | float (numeric value between 1.0 and 30.0)in 'Guidance Scale' Slider component
    "juggernautXL_version6Rundiffusion.safetensors",    # str (Option from: ['juggernautXL_version6Rundiffusion.safetensors', 'realisticStockPhoto_v10.safetensors', 'bluePencilXL_v050.safetensors', 'DreamShaper_8_pruned.safetensors'])in 'Base Model (SDXL only)' Dropdown component
    "None", # str (Option from: ['None', 'juggernautXL_version6Rundiffusion.safetensors', 'realisticStockPhoto_v10.safetensors', 'bluePencilXL_v050.safetensors', 'DreamShaper_8_pruned.safetensors'])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
    "None", # str (Option from: ['None', 'sd_xl_offset_example-lora_1.0.safetensors', 'SDXL_FILM_PHOTOGRAPHY_STYLE_BetaV0.4.safetensors', 'sdxl_lcm_lora.safetensors'])in 'LoRA 1' Dropdown component
    -2, # int | float (numeric value between -2 and 2)in 'Weight' Slider component
    "None", # str (Option from: ['None', 'sd_xl_offset_example-lora_1.0.safetensors', 'SDXL_FILM_PHOTOGRAPHY_STYLE_BetaV0.4.safetensors', 'sdxl_lcm_lora.safetensors'])in 'LoRA 2' Dropdown component
    -2, # int | float (numeric value between -2 and 2)in 'Weight' Slider component
    "None", # str (Option from: ['None', 'sd_xl_offset_example-lora_1.0.safetensors', 'SDXL_FILM_PHOTOGRAPHY_STYLE_BetaV0.4.safetensors', 'sdxl_lcm_lora.safetensors'])in 'LoRA 3' Dropdown component
    -2, # int | float (numeric value between -2 and 2)in 'Weight' Slider component
    "None", # str (Option from: ['None', 'sd_xl_offset_example-lora_1.0.safetensors', 'SDXL_FILM_PHOTOGRAPHY_STYLE_BetaV0.4.safetensors', 'sdxl_lcm_lora.safetensors'])in 'LoRA 4' Dropdown component
    -2, # int | float (numeric value between -2 and 2)in 'Weight' Slider component
    "None", # str (Option from: ['None', 'sd_xl_offset_example-lora_1.0.safetensors', 'SDXL_FILM_PHOTOGRAPHY_STYLE_BetaV0.4.safetensors', 'sdxl_lcm_lora.safetensors'])in 'LoRA 5' Dropdown component
    -2, # int | float (numeric value between -2 and 2)in 'Weight' Slider component
    True,   # bool in 'Input Image' Checkbox component
    "Howdy!",   # str in 'parameter_73' Textbox component
    "Disabled", # str in 'Upscale or Variation:' Radio component
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==",   # str (filepath or URL to image)in 'Drag above image to here' Image component
    ["Left"],   # List[str] in 'Outpaint Direction' Checkboxgroup component
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==",   # str (filepath or URL to image)in 'Drag above image to here' Image component
    "Howdy!",   # str in 'Inpaint Additional Prompt' Textbox component
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==",   # 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
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==",   # 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
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==",   # 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
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==",   # 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=29
)
print(result)

its working for me