mrhan1993 / Fooocus-API

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

Where to put the prompt? #220

Closed idris67 closed 4 months ago

idris67 commented 4 months ago

Sorry for the noob question, but when I run "python main.py" on command line, I don't know where to input my prompt to make the image? I wanted to generate images programatically, hence why I'm interested in the Fooocus-API project, but I don't know where to input my basic prompts. Thanks for any suggestion!

mrhan1993 commented 4 months ago

you can find examples in examples folder

idris67 commented 4 months ago

you can find examples in examples folder

I'm sorry in the example.py there is only a "img_prompt_params" and even if I add an image_prompts to it, and run the example script I just get a bunch of errors. Even if I move this script in the main folder, or add this part in the config.txt and run the main.py instead... I wish there was a small tutorial for running this

imwito commented 4 months ago

You should first run Fooocus-API correctly according to the Readme. If you want to generate images, this is the sample code to call the text-to-image api, don't add this code to main.py or config.txt, you can create a new python file and run it.

import requests
import json

# Vincent diagram example

host = "http://127.0.0.1:8888"

def text2img(params: dict) -> dict:
    """
    Vincentian picture
    """
    result = requests.post(url=f"{host}/v1/generation/text-to-image",
                           data=json.dumps(params),
                           headers={"Content-Type": "application/json"})
    return result.json()

result = text2img(
        {"prompt": "1girl sitting on the ground",
         "async_process": True}
    )
print(result)
idris67 commented 4 months ago

You should first run Fooocus-API correctly according to the Readme. If you want to generate images, this is the sample code to call the text-to-image api, don't add this code to main.py or config.txt, you can create a new python file and run it.

import requests
import json

# Vincent diagram example

host = "http://127.0.0.1:8888"

def text2img(params: dict) -> dict:
    """
    Vincentian picture
    """
    result = requests.post(url=f"{host}/v1/generation/text-to-image",
                           data=json.dumps(params),
                           headers={"Content-Type": "application/json"})
    return result.json()

result = text2img(
        {"prompt": "1girl sitting on the ground",
         "async_process": True}
    )
print(result)

Omg thank you so much! So have to first run main.py and then your example. Thanks a lot 🙏