Spaces:
Running
Running
File size: 6,718 Bytes
8dc695b df3c6eb 8dc695b ecda46a df3c6eb 6f0e2d4 8dc695b df3c6eb b855474 df3c6eb ecda46a 8dc695b d346aac 8dc695b df3c6eb ecda46a 8dc695b b855474 ecda46a b855474 8dc695b ecda46a d4fabb4 b855474 ecda46a d4fabb4 ecda46a d4fabb4 ecda46a d4fabb4 8dc695b ecda46a d346aac 60733cc b855474 ecda46a 8dc695b ecda46a d4fabb4 b855474 ecda46a d4fabb4 ecda46a d4fabb4 ecda46a d4fabb4 ecda46a df3c6eb b855474 ecda46a df3c6eb ecda46a df3c6eb ecda46a 8dc695b ecda46a 8dc695b ecda46a 8dc695b ecda46a 8dc695b ecda46a 60733cc ecda46a 60733cc ecda46a d4fabb4 ecda46a 8dc695b ecda46a 60733cc 8dc695b ecda46a df3c6eb ecda46a 60733cc ecda46a df3c6eb 8dc695b 72c5a93 | 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
from diffusers import DiffusionPipeline
import torch
import re
import time
import soundfile as sf
from qwen_tts import Qwen3TTSModel
from langdetect import detect
import os
device = "cuda" if torch.cuda.is_available() else "cpu"
# --- Chat Logic ---
chat_models = {
"Normal": "Qwen/Qwen3-0.6B",
"Thinking": "Qwen/Qwen2.5-1.5B-Instruct"
}
loaded_chat_models = {}
loaded_chat_tokenizers = {}
def load_chat_model(mode):
model_id = chat_models[mode]
if model_id not in loaded_chat_models:
gr.Info(f"Loading {mode} Brain...")
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32,
device_map="auto"
)
loaded_chat_models[model_id] = model
loaded_chat_tokenizers[model_id] = tokenizer
return "Status: π’ Loaded"
return "Status: π’ Loaded"
def chat_logic(user_input, mode):
model_id = chat_models[mode]
if model_id not in loaded_chat_models:
return "β Please click 'Load Model' first!"
model, tokenizer = loaded_chat_models[model_id], loaded_chat_tokenizers[model_id]
messages = [{"role": "user", "content": user_input}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(**model_inputs, max_new_tokens=1024)
response = tokenizer.batch_decode([generated_ids[0][len(model_inputs.input_ids[0]):]], skip_special_tokens=True)[0]
return re.sub(r'<think>.*?</think>\s*\n?', '', response, flags=re.DOTALL).strip()
# --- Image Logic ---
image_model_id = "stabilityai/sdxl-turbo"
image_pipe = None
def load_image_model():
global image_pipe
if image_pipe is None:
gr.Info("Priming TNT Engine...")
pipe = DiffusionPipeline.from_pretrained(
image_model_id,
torch_dtype=torch.float16 if device == "cuda" else torch.float32
)
pipe.to(device)
image_pipe = pipe
return "Status: π’ Loaded"
return "Status: π’ Loaded"
def image_logic(prompt, width, height, steps):
if image_pipe is None:
yield "β Load Model First", None
return
yield "π₯ IGNITING...", None
image = image_pipe(
prompt=prompt,
width=int(width),
height=int(height),
num_inference_steps=int(steps),
guidance_scale=0.0
).images[0]
yield "π₯ EXPLODED", image
# --- TTS Logic ---
tts_model_id = "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice"
SUPPORTED_VOICES = ['aiden', 'dylan', 'eric', 'ono_anna', 'ryan', 'serena', 'sohee', 'uncle_fu', 'vivian']
tts_model = None
def load_tts_model():
global tts_model
if tts_model is None:
gr.Info("Tuning Note-Blocks...")
tts_model = Qwen3TTSModel.from_pretrained(
tts_model_id,
device_map=device,
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32
)
return "Status: π’ Loaded"
return "Status: π’ Loaded"
def tts_logic(text, voice, inst, auto):
if tts_model is None:
return None, "Status: β Not Loaded"
try:
wavs, sr = tts_model.generate_custom_voice(
language="English",
speaker=voice,
instruct=inst,
text=text
)
output_path = "creeper_voice.wav"
sf.write(output_path, wavs[0], sr)
return output_path, "Status: π’ Audio Generated"
except Exception as e:
return None, f"Status: β Error: {str(e)}"
# --- UI Styles ---
creeper_css = """
body { background-color: #000000; }
.gradio-container { background-color: #1e1e1e; border: 8px solid #2e8b57; color: #00ff00; }
.small-status { font-size: 0.8em; color: #2e8b57; margin-top: -10px; }
.gr-button-primary { background-color: #4A7023 !important; border: 2px solid #000 !important; }
"""
with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
gr.Markdown("# π© CREEPER AI HUB π©")
with gr.Tabs():
# --- Chat Tab ---
with gr.TabItem("SSSSS-CHAT"):
with gr.Row():
chat_status = gr.Markdown("Status: π΄ Not Loaded", elem_classes=["small-status"])
with gr.Row():
mode_radio = gr.Radio(["Normal", "Thinking"], value="Normal", label="Brain Mode")
load_chat_btn = gr.Button("Load Model")
chat_in = gr.Textbox(label="Message", lines=3)
chat_out = gr.Textbox(label="Creeper Says")
chat_btn = gr.Button("EXPLODE TEXT", variant="primary")
load_chat_btn.click(load_chat_model, mode_radio, chat_status)
chat_btn.click(chat_logic, [chat_in, mode_radio], chat_out)
# --- Image Tab ---
with gr.TabItem("TNT-IMAGE"):
with gr.Row():
img_status = gr.Markdown("Status: π΄ Not Loaded", elem_classes=["small-status"])
with gr.Row():
img_prompt = gr.Textbox(label="Visual Idea", placeholder="Pixel art forest...")
load_img_btn = gr.Button("Load Model")
with gr.Row():
w_s = gr.Slider(256, 1024, 512, step=64, label="Width")
h_s = gr.Slider(256, 1024, 512, step=64, label="Height")
s_s = gr.Slider(1, 10, 4, step=1, label="Steps")
img_btn = gr.Button("EXPLODE IMAGE", variant="primary")
img_out = gr.Image(label="Output")
load_img_btn.click(load_image_model, None, img_status)
img_btn.click(image_logic, [img_prompt, w_s, h_s, s_s], [img_status, img_out])
# --- TTS Tab ---
with gr.TabItem("NOTE-BLOCK"):
with gr.Row():
tts_status = gr.Markdown("Status: π΄ Not Loaded", elem_classes=["small-status"])
with gr.Row():
voice_sel = gr.Dropdown(SUPPORTED_VOICES, value="vivian", label="Speaker")
load_tts_btn = gr.Button("Load Model")
tts_in = gr.Textbox(label="Text to Speak")
style_in = gr.Textbox("Speak naturally", label="Instructions")
tts_btn = gr.Button("EXPLODE AUDIO", variant="primary")
aud_out = gr.Audio(label="Audio Output")
load_tts_btn.click(load_tts_model, None, tts_status)
tts_btn.click(tts_logic, [tts_in, voice_sel, style_in, gr.State(True)], [aud_out, tts_status])
if __name__ == "__main__":
demo.launch(mcp_server=False)
|