FooocusAPI en_us Help

Text to image

This is the simplest case, and even if you have no specific idea, you can send an empty data request, and it will still work.

import requests host = 'http://127.0.0.1:7866' endpoint = '/v1/engine/generate' params = {} response = requests.post(host + endpoint, json=params) print(response.json())

It's as simple as that. In reality, there's nothing difficult about it. After that, you'll receive a JSON string, and by extracting the content from result, you'll get the link to the image that was just generated.

{ "req_params": { ... }, "start_mills": 1722075451526, "task_status": "finished", "webhook_url": "", "task_id": "7a5e0a4598af40f6a0db0f9f65b54900", "id": 131, "in_queue_mills": 1722075451319, "finish_mills": 1722075469000, "progress": 100, "result": [ "http://127.0.0.1:7866/outputs/2024-07-27/2024-07-27_18-17-48_9183.png" ] }

Actually, as mentioned at the beginning of the documentation, regardless of which type of generation is performed, the actual processing method is the same. The only difference is in the parameters, so you can encapsulate it into a method:

import requests def generate_image( host: str = 'http://127.0.0.1:7866', endpoint: str = '/v1/engine/generate', params: dict = {} ) -> dict: """ :host: server host :endpoint: server endpoint :params: request params :return: response json """ return requests.post(host + endpoint, json=params).json()
Last modified: 03 八月 2024