Spaces:
Sleeping
Sleeping
up3
Browse files
app.py
CHANGED
|
@@ -17,15 +17,22 @@ from Gradio_UI import GradioUI
|
|
| 17 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 18 |
@tool
|
| 19 |
def inference_image_tool(prompt: str, model: str = "black-forest-labs/FLUX.1-dev") -> "Image.Image":
|
| 20 |
-
"""Generate an image from a text prompt using Hugging Face Inference Providers."
|
| 21 |
Args:
|
| 22 |
prompt: Text prompt for the image.
|
| 23 |
model: HF model id (e.g. black-forest-labs/FLUX.1-dev)."""
|
| 24 |
token = os.getenv("HF_TOKEN")
|
| 25 |
if not token:
|
| 26 |
raise RuntimeError("HF_TOKEN is missing. Add it in Space Settings → Secrets.")
|
|
|
|
| 27 |
client = InferenceClient(provider="auto", api_key=token)
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
@tool
|
|
|
|
| 17 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 18 |
@tool
|
| 19 |
def inference_image_tool(prompt: str, model: str = "black-forest-labs/FLUX.1-dev") -> "Image.Image":
|
| 20 |
+
"""Generate an image from a text prompt using Hugging Face Inference Providers. Return a local file path to a PNG."
|
| 21 |
Args:
|
| 22 |
prompt: Text prompt for the image.
|
| 23 |
model: HF model id (e.g. black-forest-labs/FLUX.1-dev)."""
|
| 24 |
token = os.getenv("HF_TOKEN")
|
| 25 |
if not token:
|
| 26 |
raise RuntimeError("HF_TOKEN is missing. Add it in Space Settings → Secrets.")
|
| 27 |
+
|
| 28 |
client = InferenceClient(provider="auto", api_key=token)
|
| 29 |
+
img = client.text_to_image(prompt, model=model) # PIL.Image
|
| 30 |
+
|
| 31 |
+
out_dir = "/tmp/agent_images"
|
| 32 |
+
os.makedirs(out_dir, exist_ok=True)
|
| 33 |
+
out_path = os.path.join(out_dir, f"{uuid.uuid4().hex}.png")
|
| 34 |
+
img.save(out_path)
|
| 35 |
+
return out_path
|
| 36 |
|
| 37 |
|
| 38 |
@tool
|