Spaces:
Sleeping
Sleeping
File size: 2,081 Bytes
678d74e 9e2257b 678d74e 9e2257b 678d74e 9e2257b 678d74e 9e2257b 3e10159 9e2257b 678d74e 3e10159 678d74e 9e2257b 678d74e 9e2257b 678d74e 9e2257b 678d74e 9e2257b 678d74e 9e2257b 678d74e 9e2257b 678d74e 9e2257b 678d74e 3e10159 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import gradio as gr
from huggingface_hub import InferenceClient
import os
from PIL import Image
# Initialize the HF Inference Client
client = InferenceClient(token=os.getenv("HF_TOKEN"))
MODELS = {
"Flux.1 [Schnell]": "black-forest-labs/FLUX.1-schnell",
"Pony XL (Animagine)": "cagliostrolab/animagine-xl-3.1"
}
def generate_image(prompt, model_choice):
if not prompt or prompt.strip() == "":
return None
model_id = MODELS.get(model_choice, MODELS["Flux.1 [Schnell]"])
try:
image = client.text_to_image(prompt, model=model_id)
return image
except Exception as e:
raise gr.Error(f"Neural Core Error: {str(e)}")
# UI Styling
custom_css = """
footer {visibility: hidden}
body { background-color: #030303 !important; }
.gradio-container { border: none !important; }
#gen-button { background: #ffffff !important; color: #000000 !important; font-weight: 900 !important; }
"""
# Fixed: Removed gr.Div (unsupported) and moved theme/css to launch() for Gradio 6 compatibility
with gr.Blocks() as demo:
gr.Markdown("# CODEX_VISION", elem_id="title")
gr.Markdown("### NEURAL PROJECTION INTERFACE")
with gr.Row():
with gr.Column(scale=1):
prompt = gr.Textbox(
label="Prompt",
placeholder="Describe what you want to see...",
lines=3
)
model = gr.Radio(
choices=list(MODELS.keys()),
value="Flux.1 [Schnell]",
label="Engine"
)
btn = gr.Button("Initialize Visualization", variant="primary", elem_id="gen-button")
with gr.Column(scale=1):
output = gr.Image(label="Projection Result", type="pil")
btn.click(
fn=generate_image,
inputs=[prompt, model],
outputs=output
)
if __name__ == "__main__":
# Gradio 6.0 compatible launch
demo.queue().launch(
css=custom_css,
theme=gr.themes.Default(primary_hue="zinc", secondary_hue="zinc")
)
|