Text-to-Image / app.py
LuigiLui's picture
Update app.py
3901554 verified
raw
history blame
1.98 kB
import gradio as gr
import random
model = gr.load("models/Purz/face-projection")
def generate_image(text, seed):
if seed is not None:
random.seed(seed)
return model(text)
examples = [
["Humanoid Cat Warrior, Full View", None],
["Warhammer Sisterhood", None],
["Future Robots war", None],
["Fantasy dragon", None]
]
# Custom CSS for minimalist style, horizontal example layout, and styled prompt box
custom_css = """
/* Remove border and background color for the output image preview */
.output-image {
border: none !important;
background: none !important;
}
/* Prompt textbox styling */
input[type="text"] {
border: 2px solid #ddd;
border-radius: 8px;
padding: 12px;
font-size: 16px;
width: 100%;
background-color: #f9f9f9;
}
/* Examples arranged in a single line, without buttons */
.gr-examples {
display: flex;
flex-direction: row;
justify-content: space-evenly;
gap: 10px;
margin-top: 10px;
}
.gr-examples span {
font-size: 14px;
color: #333;
cursor: pointer;
padding: 5px;
transition: all 0.2s ease;
}
/* Hover effect on examples */
.gr-examples span:hover {
color: #007bff;
text-decoration: underline;
}
"""
# Function to handle example clicks (to simulate button-less selection)
def update_prompt_text(example_text):
return example_text, None
# Gradio Interface with updated UI elements and custom CSS
interface = gr.Interface(
fn=generate_image,
inputs=[
gr.Textbox(label="Imagine anything:", placeholder="Describe the scene...", interactive=True),
gr.Slider(minimum=0, maximum=10000, step=1, label="Seed (optional)")
],
outputs=gr.Image(label="Generated Image", type="pil"),
examples=examples,
css=custom_css, # Apply custom CSS
description="Enter a creative prompt or choose an example to generate your AI-powered image. Model performance may vary due to CPU usage.",
live=True
)
interface.launch()