Spaces:
No application file
Create app.py
Browse filesimport 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()
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
import osimport gradio as grfrom 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()