Spaces:
No application file

Owner

import os
import gradio as gr
from huggingface_hub import InferenceClient

MODEL = "black-forest-labs/FLUX.1-schnell"

def generer_image(prompt):
if not prompt or not prompt.strip():
raise gr.Error("Décris l'image que tu veux créer.")

token = os.environ.get("HF_TOKEN")
if not token:
    raise gr.Error(
        "Le secret HF_TOKEN doit être configuré "
        "dans les paramètres du Space."
    )

try:
    client = InferenceClient(api_key=token)

    image = client.text_to_image(
        prompt.strip(),
        model=MODEL
    )

    return image

except Exception as e:
    raise gr.Error(
        f"Échec de génération : {str(e)[:300]}"
    )

with gr.Blocks(title="CréaIA Congo") as demo:
gr.Markdown(
"# CréaIA Congo 🇨🇩\n"
"### Transforme tes idées en images avec l'IA."
)

prompt = gr.Textbox(
    label="Décris ton image",
    placeholder="Une ville futuriste à Kinshasa au coucher du soleil...",
    lines=3
)

bouton = gr.Button("Générer mon image", variant="primary")
image = gr.Image(label="Résultat", type="pil")

bouton.click(
    fn=generer_image,
    inputs=prompt,
    outputs=image
)

demo.launch()

Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment