Spaces:
Sleeping
Sleeping
import gradio as gr | |
import random | |
import torch # Assuming your model is compatible with PyTorch for GPU use | |
# Load the model once at startup (GPU-optimized if available) | |
device = "cuda" if torch.cuda.is_available() else "cpu" | |
model = gr.load("models/Purz/face-projection").to(device) | |
# Function to generate the image | |
def generate_image(text, seed): | |
if seed is not None: | |
random.seed(seed) | |
# Generate image using the model, ensure device compatibility | |
return model(text).to("cpu") # Move to CPU if Gradio doesn't support GPU display | |
# Define example inputs | |
examples = [ | |
["Humanoid Cat Warrior, Full View", None], | |
["Warhammer Sisterhood", None], | |
["Future Robots war", None], | |
["Fantasy dragon", None] | |
] | |
# Customized Gradio Interface with faster processing optimizations | |
interface = gr.Interface( | |
fn=generate_image, | |
inputs=[ | |
gr.Textbox(label="Imagine and Type Here:", placeholder="Type your idea or click an example...", elem_id="input-text"), | |
gr.Slider(minimum=0, maximum=10000, step=1, label="Seed (optional)", elem_id="seed-slider") | |
], | |
outputs=gr.Image(label="Generated Image", elem_id="output-image"), | |
examples=examples, | |
theme="default", | |
description="The model is currently running on GPU for faster processing. Thanks for your patience.", | |
css=""" | |
#input-text, #seed-slider .input-label, .output-label, .description { | |
font-family: 'Arial', sans-serif; | |
text-align: center; | |
color: #333; | |
} | |
.container { | |
background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%); | |
border-radius: 12px; | |
padding: 10px; | |
} | |
.btn { | |
background: linear-gradient(90deg, #ff8a00, #e52e71); | |
border: none; | |
border-radius: 25px; | |
color: white; | |
padding: 12px 24px; | |
font-size: 16px; | |
font-weight: bold; | |
cursor: pointer; | |
} | |
.examples-table { | |
text-align: center; | |
} | |
""" | |
) | |
# Launch the interface | |
interface.launch() |