Initial commit
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# utils/api_client.py
|
||||
import requests
|
||||
import json
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger("ComfyGallery.API")
|
||||
|
||||
class ComfyAPIClient:
|
||||
def __init__(self, base_url: str = "http://127.0.0.1:8000"):
|
||||
self.base_url = base_url.rstrip("/")
|
||||
|
||||
def send_prompt(self, prompt_json_str: str) -> bool:
|
||||
if not prompt_json_str:
|
||||
return False
|
||||
try:
|
||||
prompt_data = json.loads(prompt_json_str)
|
||||
payload = {"prompt": prompt_data}
|
||||
url = f"{self.base_url}/prompt"
|
||||
response = requests.post(url, json=payload, timeout=4)
|
||||
if response.status_code == 200:
|
||||
return True
|
||||
else:
|
||||
logger.error(f"Ошибка API ComfyUI: {response.status_code} - {response.text}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Не удалось подключиться к ComfyUI по адресу {self.base_url}: {e}")
|
||||
return False
|
||||
Reference in New Issue
Block a user