|
import gradio as gr |
|
import random |
|
import os |
|
from llama_cpp import Llama |
|
|
|
|
|
model_versions = { |
|
"WizzGPTv3": "model/WizzGPTv3-q8_0.gguf", |
|
"WizzGPTv6": "model/WizzGPTv6-q8_0.gguf", |
|
"WizzGPTv7": "model/WizzGPTv7-q8_0.gguf" |
|
} |
|
|
|
|
|
llm = None |
|
current_model = "WizzGPTv7" |
|
model_name = model_versions[current_model] |
|
|
|
|
|
def load_model(model_name): |
|
global llm, current_model |
|
model_path = model_versions[model_name] |
|
if not os.path.exists(model_path): |
|
raise FileNotFoundError(f"Model file not found at {model_path}") |
|
llm = Llama( |
|
model_path=model_path, |
|
n_ctx=1024, |
|
n_threads=2, |
|
n_batch=256, |
|
verbose=False |
|
) |
|
current_model = model_name |
|
|
|
|
|
load_model(current_model) |
|
|
|
|
|
prompt_list = [ |
|
"A beautiful sunset over", |
|
"A macro shot of", |
|
"Award winning photography of", |
|
"Wide shot of", |
|
"The intricate details of", |
|
"The portrait of a", |
|
"A resin figurine of", |
|
"Painting of", |
|
"A delicate", |
|
"A rustic", |
|
"A stunningly beautiful", |
|
"Masterpiece, best quality", |
|
"Hyperrealistic shot of a", |
|
"Professional fashion shot of", |
|
"Photo of a classy", |
|
"Photo of a glamour", |
|
"(Horror) shot of", |
|
"Cinematic film still of", |
|
"A (monochrome:2) photography of", |
|
"A ", |
|
"Masterpiece, best quality, ultra-detailed,", |
|
"A hyper-realistic, cinematic shot of", |
|
"An incredibly detailed, high-resolution portrait of", |
|
"A breathtaking, photorealistic capture of", |
|
"A vivid, intricately detailed scene of", |
|
"A surreal, ultra-detailed rendering of", |
|
"An exquisitely detailed, cinematic masterpiece of", |
|
"A mesmerizing, hyper-detailed view of", |
|
"A stunning, ultra-realistic depiction of", |
|
"A visually arresting, high-definition snapshot of", |
|
"The ", |
|
"The (hologram) of", |
|
"A surrealist art of", |
|
"The (photography of a __animal__:2), (full-body),", |
|
"The (photo of a (__animal__:__animal__:__weight__) hybrid), full-body,", |
|
"A photo of an Eldritch abomination,", |
|
"A (3D geometrically printed figurine) of", |
|
"An overwhelmingly beautiful", |
|
"An (eerie scene) featuring", |
|
"A serene landscape showcasing", |
|
"A photography of a magnificent", |
|
"A bokeh effect background with", |
|
"The bustling streets of", |
|
"A whimsical depiction of", |
|
"A dramatic aerial view of", |
|
"An enchanting tableau presenting", |
|
"The ancient ruins of", |
|
"A night sky filled with", |
|
"A macro close-up portrait of", |
|
"An (abstract composition) with", |
|
"A snowy scene with", |
|
"The golden hour lighting up", |
|
"A mystical forest where", |
|
"A futuristic cityscape with", |
|
"An ethereal", |
|
"A whimsical", |
|
"Photo of an amazingly beautiful creature with", |
|
"Photo of an iridescent", |
|
"Focus on", |
|
"A meticulously crafted", |
|
"A dramatic chiaroscuro lighting of", |
|
"An artistic interpretation of", |
|
"A vivid depiction of", |
|
"A serene moment captured in", |
|
"A richly textured", |
|
"An evocative scene portraying", |
|
"An epic panorama of", |
|
"An iconic representation of", |
|
"A minimalist composition featuring", |
|
"An avant-garde portrayal of", |
|
"An immersive diorama of", |
|
"A time-lapse sequence showing", |
|
"A haunting silhouette against", |
|
"An ancient mythological scene in", |
|
"A contemporary reimagining of", |
|
"A hyper-detailed rendering of", |
|
"A nostalgic memory preserved in", |
|
"A powerful juxtaposition of", |
|
"A seamless blend of", |
|
"A surreal", |
|
"An evocative interplay of light and shadow", |
|
"A preserved fragment of", |
|
"An intricate lacework of", |
|
"An offbeat take on", |
|
"A reflective surface capturing", |
|
"A slow-motion capture of", |
|
"A stunning vista showcasing", |
|
"A timeless black-and-white portrait of", |
|
"A twisted version of", |
|
"A dynamic motion blur effect in", |
|
"A geometric pattern inspired by", |
|
"A moody fog enveloping", |
|
"A textured overlay on", |
|
"A vibrant explosion of color", |
|
"A carefully orchestrated symmetry in", |
|
"A kaleidoscopic arrangement of", |
|
"A subtle gradation of color in", |
|
"The raw grandeur of", |
|
"A whirlwind of movement in", |
|
"A conceptual representation of", |
|
"An experimental take on", |
|
"A harmonious blend of", |
|
"A poetic rendering of", |
|
"An organic flow of", |
|
"An understated elegance in", |
|
"An unassuming grace in", |
|
"A dynamic shift in", |
|
"A gentle harmony of", |
|
"A graceful curve in", |
|
"A heightened sense of", |
|
"A radiant glow surrounding", |
|
"A resonant soundscape in visual form", |
|
"A strong focal point in", |
|
"An angular perspective on", |
|
"A fleeting moment of", |
|
"A playful interaction between", |
|
"A stark minimalist design featuring", |
|
"A whimsical journey through", |
|
"An organic structure evolving from", |
|
"A visual metaphor for", |
|
"A window into another world through a Stable-Diffusion of", |
|
"A delicate balance between", |
|
"A seamless transition from", |
|
"A tranquil scene", |
|
"The vibrant colors of", |
|
"A peaceful countryside morning in", |
|
"An underwater world revealing", |
|
"The photography of", |
|
"A (2000s vintage RAW photo) of", |
|
"Photoshoot of", |
|
"A breathtaking", |
|
"An extremely detailed", |
|
"An establishing shot of", |
|
"A concept art of", |
|
"A breathtaking portrait of a majestic", |
|
"A charcoal sketch of", |
|
"A dramatic scene of", |
|
"A painting in the style of", |
|
"An isolated", |
|
"An (upper angle shot) of", |
|
"An (aerial perspective photo) of a", |
|
"A high contrast side light scene", |
|
"A dark And mysterious ", |
|
"A clay sculpture of", |
|
"A digital illustration featuring", |
|
"A graffiti art piece depicting", |
|
"A historical reenactment of", |
|
"A leading lines shot of", |
|
"A low angle view of", |
|
"A misty dawn over", |
|
"A mixed media collage showcasing", |
|
"A panoramic view of", |
|
"A pastel portrait of", |
|
"A pencil drawing of", |
|
"A tight shot of", |
|
"A watercolor painting of", |
|
"A National Geographic wildlife photographer capturing", |
|
"A worm's eye view of", |
|
"An ink drawing depicting", |
|
"Masterpiece,", |
|
"A mesmerizing glimpse of", |
|
"A captivating display of", |
|
"A dynamic interplay of", |
|
"A sublime vision of", |
|
"A breathtaking portrayal of", |
|
"A poetic interpretation of", |
|
"A striking composition of", |
|
"A vivid tapestry of", |
|
"An enigmatic depiction of", |
|
"A remarkable fusion of", |
|
"A stunning perspective of", |
|
"A harmonious blend of", |
|
"A radical reinterpretation of", |
|
"A delicate sketch of", |
|
"A vibrant composition of", |
|
"A richly textured portrayal of", |
|
"A pioneering outlook of", |
|
"A refined portrait of", |
|
"A sharp focus on", |
|
"A monumental depiction of", |
|
"A fluid rendering of", |
|
"A kinetic expression of", |
|
"A graceful outline of", |
|
"A provocative framework of", |
|
"A subtle balance of", |
|
"A minimalist construction of", |
|
"A dramatic evolution of", |
|
"A whimsical abstraction of", |
|
"A poignant reflection of", |
|
"A pioneering illustration of", |
|
"A sophisticated visualization of", |
|
"An exuberant composition of", |
|
"A bold expression of", |
|
"A lavish interpretation of", |
|
"A masterful arrangement of", |
|
"A futuristic vision of", |
|
"A radiant convergence of", |
|
"A surrealist portrayal of", |
|
"A fragmented mosaic of", |
|
"A cryptic collage of", |
|
"A crystalline perspective on", |
|
"A dreamlike rendition of", |
|
"A kinetic study of", |
|
"A spontaneous capture of", |
|
"A reflective moment of", |
|
"An intense interplay of", |
|
"A layered narrative of", |
|
"A refined synthesis of", |
|
"A chiaroscuro play of", |
|
"A poetic exploration of", |
|
"A reimagined concept of", |
|
"A vigorous depiction of", |
|
"A textured cascade of", |
|
"A visionary abstraction of", |
|
"A monumental snapshot of", |
|
"A scintillating vignette of", |
|
"A graceful melding of", |
|
"A spectral composition of", |
|
"A radiant interplay of", |
|
"A striking juxtaposition of", |
|
"A refined montage of", |
|
"A nuanced portrayal of", |
|
"A visionary construct of", |
|
"An evocative snapshot of", |
|
"A bold fusion of", |
|
"A delicate overlay of", |
|
"A complex layering of", |
|
"A vivid gradient of", |
|
"A kinetic cascade of", |
|
"A luminous texture of", |
|
"A bold silhouette of", |
|
"A high-resolution photographic capture of", |
|
"A sharply focused photographic study of", |
|
"A meticulously framed photographic moment of", |
|
"An ultra-detailed photographic exploration of", |
|
"A dynamic high-contrast photographic depiction of", |
|
"A bold, hyper-realistic photographic rendering of", |
|
"An intimate photographic snapshot of", |
|
"A vividly composed photographic portrayal of", |
|
"A crisp, professional photographic impression of", |
|
"A timeless black-and-white photographic record of", |
|
"A vividly detailed photographic vignette of", |
|
"A dynamic, low-key photographic interpretation of", |
|
"A refined photographic montage of", |
|
"A compelling photographic narrative of", |
|
"A striking high-key photographic expression of", |
|
"A meticulously captured photographic scene of", |
|
"A visionary photographic perspective on", |
|
"An innovative photographic framing of", |
|
"A sophisticated photographic series of", |
|
"A powerful photographic study of", |
|
"A radiant photographic tableau of", |
|
"A minimalist photographic composition of", |
|
"An edgy photographic take on", |
|
"A vibrant photographic freeze-frame of", |
|
"A kinetic photographic capture of", |
|
"A meticulously arranged photographic display of", |
|
"A dramatic photographic snapshot of", |
|
"A crisp, color-rich photographic impression of", |
|
"A bold photographic experiment capturing", |
|
"An avant-garde photographic reinterpretation of", |
|
"A sharply rendered photographic moment of", |
|
"A compelling photographic sequence of", |
|
"A profound photographic observation of", |
|
"A refined photographic layering of", |
|
"A spontaneous photographic capture of", |
|
"A surreal photographic juxtaposition of", |
|
"A masterfully composed photographic glimpse of", |
|
"A radiant photographic slice of", |
|
"A detailed photographic capture of", |
|
"A visually arresting photographic study of" |
|
] |
|
|
|
|
|
def generate_completions(prompt, n_responses, max_tokens, temperature, top_p, top_k, repeat_penalty): |
|
results = [] |
|
print("\n" + "="*50) |
|
print(f"[PROMPT] {prompt}") |
|
print(f"[PARAMS] Completions: {n_responses}, max_tokens: {max_tokens}, temp: {temperature}, top_p: {top_p}, top_k: {top_k}, penalty: {repeat_penalty}") |
|
|
|
for _ in range(n_responses): |
|
output = llm( |
|
prompt, |
|
max_tokens=max_tokens, |
|
temperature=temperature, |
|
top_p=top_p, |
|
top_k=top_k, |
|
repeat_penalty=repeat_penalty, |
|
echo=False |
|
) |
|
text = output["choices"][0]["text"].strip() |
|
full = f"{prompt} {text}" |
|
results.append(full) |
|
print(f"[RESPONSE] {full}") |
|
|
|
print("="*50 + "\n") |
|
return "\n\n".join(results) |
|
|
|
|
|
def set_random_prompt(n): |
|
selected = random.choice(prompt_list) |
|
return selected, f"🎲 Random Prompt{'s' if n > 1 else ''}", f"🚀 Generate Prompt{'s' if n > 1 else ''}" |
|
|
|
def set_prompt_from_dropdown(choice, n): |
|
return choice, f"🎲 Random Prompt{'s' if n > 1 else ''}", f"🚀 Generate Prompt{'s' if n > 1 else ''}" |
|
|
|
def on_model_change(model_name): |
|
load_model(model_name) |
|
return f"Model loaded: {model_name}" |
|
|
|
|
|
with gr.Blocks(css=""" |
|
.gr-button { font-size: 16px; } |
|
#random-btn { height: 100%; margin: auto 0; } |
|
""") as demo: |
|
gr.Markdown("## ✨ WizzGPT — Forget logic. Embrace surprise. This model creates visual wonder, not narrative clarity.") |
|
|
|
with gr.Row(): |
|
model_selector = gr.Dropdown(choices=list(model_versions.keys()), value="WizzGPTv7", label="🧠 Select Model") |
|
model_status = gr.Textbox(value=f"Model loaded: {current_model}", label="Status", interactive=False) |
|
|
|
with gr.Group(): |
|
with gr.Row(): |
|
prompt_input = gr.Textbox(label="📝 Prompt", lines=3, placeholder="Type or pick a prompt...") |
|
with gr.Row(): |
|
prompt_dropdown = gr.Dropdown(choices=prompt_list, label="📌 Prompt Examples", scale=2) |
|
random_button = gr.Button("🎲 Random Prompt", scale=1, elem_id="random-btn") |
|
|
|
with gr.Row(): |
|
n_responses = gr.Slider(1, 7, value=1, step=1, label="Number of Completions") |
|
|
|
with gr.Accordion("⚙️ Advanced Settings", open=False): |
|
max_tokens = gr.Slider(10, 200, value=75, step=5, label="Max Tokens") |
|
temperature = gr.Slider(0.1, 2.0, value=1.10, step=0.05, label="Temperature") |
|
top_p = gr.Slider(0.0, 1.0, value=0.90, step=0.05, label="Top-p") |
|
top_k = gr.Slider(0, 128, value=40, step=1, label="Top-k") |
|
repeat_penalty = gr.Slider(0.5, 2.0, value=1.4, step=0.05, label="Repeat Penalty") |
|
|
|
generate_button = gr.Button("🚀 Generate Prompt(s)") |
|
output = gr.Textbox(label="📄 Completions", lines=12) |
|
|
|
|
|
prompt_dropdown.change(set_prompt_from_dropdown, [prompt_dropdown, n_responses], [prompt_input, random_button, generate_button]) |
|
random_button.click(set_random_prompt, inputs=n_responses, outputs=[prompt_input, random_button, generate_button]) |
|
n_responses.change(lambda n: (f"🎲 Random Prompt{'s' if n > 1 else ''}", f"🚀 Generate Prompt{'s' if n > 1 else ''}"), inputs=n_responses, outputs=[random_button, generate_button]) |
|
generate_button.click(fn=generate_completions, inputs=[prompt_input, n_responses, max_tokens, temperature, top_p, top_k, repeat_penalty], outputs=output) |
|
|
|
model_selector.change(on_model_change, inputs=model_selector, outputs=model_status) |
|
|
|
demo.launch() |