File size: 3,882 Bytes
66b0cef 0d2ed9b b3b13e2 0d2ed9b 66b0cef 0d2ed9b 5808f1f d358a03 5808f1f 0d2ed9b a841949 d358a03 a841949 d358a03 0d2ed9b d358a03 c444c71 d358a03 0d2ed9b d358a03 0d2ed9b d358a03 0d2ed9b d358a03 0d2ed9b 0f95c7c 0d2ed9b a841949 0d2ed9b a841949 0d2ed9b 73a0c03 d358a03 | 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | import gradio as gr
import threading
import os
import torch
os.environ["OMP_NUM_THREADS"] = str(os.cpu_count())
torch.set_num_threads(os.cpu_count())
model1 = gr.load("models/prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA")
model2 = gr.load("models/Purz/face-projection")
stop_event = threading.Event()
def generate_images(text, selected_model):
stop_event.clear()
if selected_model == "Turbo Realism":
model = model1
elif selected_model == "Face Projection":
model = model2
else:
return ["Invalid model selection."] * 3
results = []
for i in range(3):
if stop_event.is_set():
return ["Image generation stopped by user."] * 3
modified_text = f"{text} variation {i+1}"
result = model(modified_text)
results.append(result)
return results
def stop_generation():
"""Stops the ongoing image generation by setting the stop_event flag."""
stop_event.set()
return ["Generation stopped."] * 3
css = """
.container {
max-width: 1200px;
margin: auto;
padding: 20px;
}
.main-title {
text-align: center;
color: #1a73e8;
font-size: 2.5em;
margin-bottom: 1em;
font-weight: 700;
}
.notice {
background-color: #fef3c7;
border-left: 4px solid #f59e0b;
padding: 1em;
margin: 1em 0;
border-radius: 4px;
}
.input-group {
background-color: #f8fafc;
padding: 2em;
border-radius: 12px;
box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
margin: 1em 0;
}
.button-primary {
background-color: #1a73e8 !important;
}
.button-secondary {
background-color: #dc2626 !important;
}
.output-images {
gap: 1em;
margin-top: 2em;
}
.output-image {
border-radius: 8px;
overflow: hidden;
box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
"""
with gr.Blocks(css=css, theme=gr.themes.Soft()) as interface:
with gr.Column(elem_classes="container"):
gr.Markdown("# AI Image Generator 🎨", elem_classes="main-title")
gr.Markdown(
"⚠️ Note: Currently running on CPU mode which may affect performance.",
elem_classes="notice"
)
with gr.Group(elem_classes="input-group"):
text_input = gr.Textbox(
label="Describe your imagination",
placeholder="Enter a detailed description of the image you want to generate...",
lines=3
)
model_selector = gr.Radio(
["Turbo Realism", "Face Projection"],
label="Select Model",
value="Turbo Realism",
container=False
)
with gr.Row():
generate_button = gr.Button(
"✨ Generate Images",
elem_classes="button-primary"
)
stop_button = gr.Button(
"🛑 Stop Generation",
elem_classes="button-secondary"
)
with gr.Row(elem_classes="output-images"):
output1 = gr.Image(label="Variation 1", elem_classes="output-image")
output2 = gr.Image(label="Variation 2", elem_classes="output-image")
output3 = gr.Image(label="Variation 3", elem_classes="output-image")
gr.Markdown(
"""
### Tips for better results:
- Be specific in your descriptions
- Include details about style, mood, and lighting
- Experiment with different models for varied results
""",
)
generate_button.click(
generate_images,
inputs=[text_input, model_selector],
outputs=[output1, output2, output3]
)
stop_button.click(
stop_generation,
inputs=[],
outputs=[output1, output2, output3]
)
interface.launch() |