OTT_Bot / image_gen.py
OnlyTheTruth03's picture
Initial RAG bot
709c859
raw
history blame contribute delete
808 Bytes
import os
import requests
HF_TOKEN = os.getenv("HF_TOKEN")
if not HF_TOKEN:
raise RuntimeError("❌ HF_TOKEN not set")
API_URL = "https://router.huggingface.co/hf-inference/models/stabilityai/stable-diffusion-xl-base-1.0"
HEADERS = {
"Authorization": f"Bearer {HF_TOKEN}",
"Content-Type": "application/json"
}
def generate_image(prompt: str) -> bytes:
payload = {
"inputs": prompt,
"parameters": {
"width": 1024,
"height": 1024,
"num_inference_steps": 30,
"guidance_scale": 7.5
}
}
response = requests.post(
API_URL,
headers=HEADERS,
json=payload,
timeout=120
)
if response.status_code != 200:
raise RuntimeError(response.text)
return response.content