Text-to-Image / app.py
Jonny001's picture
Update app.py
b3b13e2 verified
raw
history blame
2.04 kB
import gradio as gr
import random
import os
# model = gr.load("models/prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA") # <-- This model is also working
model = gr.load("models/Purz/face-projection")
def generate_image(text, seed, width, height, guidance_scale, num_inference_steps):
if seed is not None:
random.seed(seed)
if text in [example[0] for example in examples]:
print(f"Using example: {text}")
result_image = model(text)
print(f"Width: {width}, Height: {height}, Guidance Scale: {guidance_scale}, Inference Steps: {num_inference_steps}")
return result_image
def randomize_parameters():
seed = random.randint(0, 999999)
width = random.randint(512, 2048)
height = random.randint(512, 2048)
guidance_scale = round(random.uniform(0.1, 20.0), 1)
num_inference_steps = random.randint(1, 40)
return seed, width, height, guidance_scale, num_inference_steps
examples = [
["Humanoid Cat Warrior, Full View", *randomize_parameters()],
["Warhammer Sisterhood", *randomize_parameters()],
["Future Robots war", *randomize_parameters()],
["Fantasy dragon", *randomize_parameters()],
]
interface = gr.Interface(
fn=generate_image,
inputs=[
gr.Textbox(label="Type here your imagination:", placeholder="Type or click an example..."),
gr.Slider(label="Seed", minimum=0, maximum=999999, step=1),
gr.Slider(label="Width", minimum=512, maximum=2048, step=64, value=1024),
gr.Slider(label="Height", minimum=512, maximum=2048, step=64, value=1024),
gr.Slider(label="Guidance Scale", minimum=0.1, maximum=20.0, step=0.1, value=3.0),
gr.Slider(label="Number of inference steps", minimum=1, maximum=40, step=1, value=28),
],
outputs=gr.Image(label="Generated Image"),
examples=examples,
theme="NoCrypt/miku",
description="Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.",
)
interface.launch()