RafacraftCoder commited on
Commit
2ca746e
·
verified ·
1 Parent(s): 2c77d7a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
+
5
+ # Usa tu token de Hugging Face (guárdalo como variable de entorno HF_TOKEN)
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
+
8
+ # Cliente de inferencia
9
+ client = InferenceClient(api_key=HF_TOKEN)
10
+
11
+ def generate_image(prompt, steps, guidance):
12
+ """
13
+ Genera una imagen con Flux.1 Schnell usando Hugging Face Inference API.
14
+ """
15
+ image = client.text_to_image(
16
+ model="black-forest-labs/flux-1-schnell", # Modelo Flux
17
+ inputs=prompt,
18
+ parameters={
19
+ "num_inference_steps": steps,
20
+ "guidance_scale": guidance
21
+ }
22
+ )
23
+ return image
24
+
25
+ # Interfaz con Gradio
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("# 🚀 Generador de imágenes con Flux.1 Schnell")
28
+ with gr.Row():
29
+ prompt = gr.Textbox(label="Prompt", value="Astronauta montando un caballo")
30
+ with gr.Row():
31
+ steps = gr.Slider(1, 50, value=5, step=1, label="Pasos de inferencia")
32
+ guidance = gr.Slider(1, 20, value=7, step=1, label="Guidance scale")
33
+ output = gr.Image(type="pil")
34
+ btn = gr.Button("Generar imagen")
35
+ btn.click(generate_image, [prompt, steps, guidance], output)
36
+
37
+ demo.launch()