Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,13 +67,19 @@ def generate_image(prompt: str) -> AgentImage:
|
|
| 67 |
Args:
|
| 68 |
prompt: The image description.
|
| 69 |
"""
|
| 70 |
-
|
| 71 |
-
if
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
final_answer = FinalAnswerTool()
|
| 79 |
|
|
|
|
| 67 |
Args:
|
| 68 |
prompt: The image description.
|
| 69 |
"""
|
| 70 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 71 |
+
if not hf_token:
|
| 72 |
+
raise RuntimeError("HF_TOKEN is missing. Add it in Settings → Variables and Secrets.")
|
| 73 |
+
|
| 74 |
+
headers = {"Authorization": f"Bearer {hf_token}", "Accept": "image/png"}
|
| 75 |
+
url = "https://api-inference.huggingface.co/models/stabilityai/sdxl-turbo"
|
| 76 |
+
|
| 77 |
+
resp = requests.post(url, headers=headers, json={"inputs": prompt}, timeout=120)
|
| 78 |
+
if resp.status_code != 200:
|
| 79 |
+
raise RuntimeError(f"Inference API error {resp.status_code}: {resp.text[:300]}")
|
| 80 |
+
|
| 81 |
+
img = Image.open(io.BytesIO(resp.content)).convert("RGB")
|
| 82 |
+
return AgentImage(img)
|
| 83 |
|
| 84 |
final_answer = FinalAnswerTool()
|
| 85 |
|