Spaces:
Sleeping
Sleeping
CryptoCreeper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from diffusers import DiffusionPipeline
|
|
| 4 |
import torch
|
| 5 |
import re
|
| 6 |
import time
|
|
|
|
| 7 |
import soundfile as sf
|
| 8 |
from qwen_tts import Qwen3TTSModel
|
| 9 |
from langdetect import detect
|
|
@@ -11,6 +12,7 @@ import os
|
|
| 11 |
|
| 12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 13 |
|
|
|
|
| 14 |
chat_models = {
|
| 15 |
"Normal": "Qwen/Qwen3-0.6B",
|
| 16 |
"Thinking": "Qwen/Qwen2.5-1.5B-Instruct"
|
|
@@ -38,17 +40,14 @@ def load_chat_model(mode):
|
|
| 38 |
def chat_logic(user_input, mode):
|
| 39 |
model_id = chat_models[mode]
|
| 40 |
if model_id not in chat_model_loaded:
|
| 41 |
-
return "β Model Not Loaded
|
| 42 |
-
|
| 43 |
model, tokenizer = loaded_chat_models[model_id], loaded_chat_tokenizers[model_id]
|
| 44 |
messages = [{"role": "user", "content": user_input}]
|
| 45 |
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 46 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 47 |
-
|
| 48 |
generated_ids = model.generate(**model_inputs, max_new_tokens=1024)
|
| 49 |
generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
|
| 50 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 51 |
-
|
| 52 |
cleaned_response = re.sub(r'<think>.*?</think>\s*\n?', '', response, flags=re.DOTALL)
|
| 53 |
return cleaned_response.strip()
|
| 54 |
|
|
@@ -59,9 +58,14 @@ def clear_chat_model(password):
|
|
| 59 |
del loaded_chat_models[model_id]
|
| 60 |
del loaded_chat_tokenizers[model_id]
|
| 61 |
chat_model_loaded.pop(model_id, None)
|
|
|
|
|
|
|
| 62 |
torch.cuda.empty_cache()
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
|
|
|
| 65 |
image_model_id = "stabilityai/sdxl-turbo"
|
| 66 |
image_pipe = None
|
| 67 |
image_model_loaded = False
|
|
@@ -69,7 +73,7 @@ image_model_loaded = False
|
|
| 69 |
def load_image_model():
|
| 70 |
global image_pipe, image_model_loaded
|
| 71 |
if image_pipe is None:
|
| 72 |
-
gr.Info("π‘ Priming TNT (
|
| 73 |
pipe = DiffusionPipeline.from_pretrained(
|
| 74 |
image_model_id,
|
| 75 |
torch_dtype=torch.float16 if device == "cuda" else torch.float32
|
|
@@ -84,11 +88,9 @@ def image_logic(prompt, width, height, steps):
|
|
| 84 |
if not image_model_loaded or image_pipe is None:
|
| 85 |
yield "β Model Not Loaded", None
|
| 86 |
return
|
| 87 |
-
|
| 88 |
start_time = time.time()
|
| 89 |
final_prompt = f"{prompt}, centered and realistic (if applicable)"
|
| 90 |
-
yield "π₯ IGNITING...
|
| 91 |
-
|
| 92 |
image = image_pipe(
|
| 93 |
prompt=final_prompt,
|
| 94 |
width=int(width),
|
|
@@ -97,7 +99,6 @@ def image_logic(prompt, width, height, steps):
|
|
| 97 |
guidance_scale=0.0,
|
| 98 |
output_type="pil"
|
| 99 |
).images[0]
|
| 100 |
-
|
| 101 |
duration = round(time.time() - start_time, 2)
|
| 102 |
yield f"π₯ EXPLODED in {duration}s", image
|
| 103 |
|
|
@@ -109,9 +110,13 @@ def clear_image_model(password):
|
|
| 109 |
del image_pipe
|
| 110 |
image_pipe = None
|
| 111 |
image_model_loaded = False
|
|
|
|
| 112 |
torch.cuda.empty_cache()
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
|
|
|
|
| 115 |
tts_model_id = "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice"
|
| 116 |
SUPPORTED_VOICES = ['aiden', 'dylan', 'eric', 'ono_anna', 'ryan', 'serena', 'sohee', 'uncle_fu', 'vivian']
|
| 117 |
tts_model = None
|
|
@@ -120,7 +125,7 @@ tts_model_loaded = False
|
|
| 120 |
def load_tts_model():
|
| 121 |
global tts_model, tts_model_loaded
|
| 122 |
if tts_model is None:
|
| 123 |
-
gr.Info("π‘ Tuning Note-Blocks (
|
| 124 |
tts_model = Qwen3TTSModel.from_pretrained(
|
| 125 |
tts_model_id,
|
| 126 |
device_map=device,
|
|
@@ -134,30 +139,21 @@ def tts_logic(text, voice, instructions, auto_detect):
|
|
| 134 |
if not tts_model_loaded or tts_model is None:
|
| 135 |
return None, "β Model Not Loaded"
|
| 136 |
try:
|
| 137 |
-
lang_map = {
|
| 138 |
-
'zh': 'Chinese', 'en': 'English', 'jp': 'Japanese',
|
| 139 |
-
'ko': 'Korean', 'de': 'German', 'fr': 'French',
|
| 140 |
-
'ru': 'Russian', 'pt': 'Portuguese', 'es': 'Spanish', 'it': 'Italian'
|
| 141 |
-
}
|
| 142 |
detected_lang = "English"
|
| 143 |
if auto_detect:
|
| 144 |
try:
|
| 145 |
raw_lang = detect(text).split('-')[0]
|
| 146 |
detected_lang = lang_map.get(raw_lang, "English")
|
| 147 |
-
except:
|
| 148 |
-
pass
|
| 149 |
-
|
| 150 |
wavs, sr = tts_model.generate_custom_voice(
|
| 151 |
-
language=detected_lang,
|
| 152 |
-
speaker=voice,
|
| 153 |
-
instruct=instructions,
|
| 154 |
-
text=text
|
| 155 |
)
|
| 156 |
output_path = "creeper_voice.wav"
|
| 157 |
sf.write(output_path, wavs[0], sr)
|
| 158 |
-
return output_path, f"
|
| 159 |
except Exception as e:
|
| 160 |
-
return None, f"
|
| 161 |
|
| 162 |
def clear_tts_model(password):
|
| 163 |
global tts_model, tts_model_loaded
|
|
@@ -167,84 +163,74 @@ def clear_tts_model(password):
|
|
| 167 |
del tts_model
|
| 168 |
tts_model = None
|
| 169 |
tts_model_loaded = False
|
|
|
|
| 170 |
torch.cuda.empty_cache()
|
| 171 |
-
|
|
|
|
|
|
|
| 172 |
|
|
|
|
| 173 |
creeper_css = """
|
| 174 |
body { background-color: #000000; }
|
| 175 |
.gradio-container { background-color: #1e1e1e; border: 10px solid #2e8b57 !important; font-family: 'Courier New', Courier, monospace; color: #00ff00; }
|
| 176 |
footer { display: none !important; }
|
| 177 |
.gr-button-primary { background-color: #4A7023 !important; border: 4px solid #000 !important; color: white !important; font-weight: bold; text-transform: uppercase; }
|
| 178 |
-
.gr-button-primary:hover { background-color: #5ea032 !important; box-shadow: 0 0 20px #2e8b57; }
|
| 179 |
label span { color: #2e8b57 !important; font-weight: bold; font-size: 1.2em; }
|
| 180 |
-
textarea, input,
|
| 181 |
-
.tabs { border-bottom: 5px solid #4A7023 !important; }
|
| 182 |
-
.tab-nav button.selected { background-color: #4A7023 !important; color: white !important; }
|
| 183 |
"""
|
| 184 |
|
| 185 |
with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
|
| 186 |
gr.Markdown("# π© CREEPER AI HUB π©")
|
| 187 |
-
|
| 188 |
with gr.Tabs():
|
| 189 |
with gr.TabItem("SSSSS-CHAT"):
|
| 190 |
-
gr.
|
| 191 |
-
chat_status_label = gr.Label("π΄ Model Not Loaded", label="Status")
|
| 192 |
with gr.Row():
|
| 193 |
-
mode_radio = gr.Radio(
|
| 194 |
-
load_chat_btn = gr.Button("Load Chat
|
| 195 |
chat_pw = gr.Textbox(label="Password", type="password")
|
| 196 |
-
clear_chat_btn = gr.Button("Clear
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
chat_btn.click(fn=chat_logic, inputs=[chat_input, mode_radio], outputs=chat_output)
|
| 204 |
-
clear_chat_btn.click(fn=clear_chat_model, inputs=chat_pw, outputs=chat_status_label)
|
| 205 |
|
| 206 |
with gr.TabItem("TNT-IMAGE"):
|
| 207 |
-
gr.
|
| 208 |
-
image_status_label = gr.Label("π΄ Model Not Loaded", label="Status")
|
| 209 |
with gr.Row():
|
| 210 |
-
with gr.Column(
|
| 211 |
-
img_prompt = gr.Textbox(label="
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
load_image_btn = gr.Button("Load Image Model")
|
| 217 |
img_btn = gr.Button("EXPLODE IMAGE", variant="primary")
|
| 218 |
img_pw = gr.Textbox(label="Password", type="password")
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
img_btn.click(fn=image_logic, inputs=[img_prompt, w_slider, h_slider, s_slider], outputs=[image_status_label, img_output])
|
| 225 |
-
clear_image_btn.click(fn=clear_image_model, inputs=img_pw, outputs=image_status_label)
|
| 226 |
|
| 227 |
with gr.TabItem("NOTE-BLOCK (TTS)"):
|
| 228 |
-
gr.
|
| 229 |
-
tts_status_label = gr.Label("π΄ Model Not Loaded", label="Status")
|
| 230 |
with gr.Row():
|
| 231 |
with gr.Column():
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
load_tts_btn = gr.Button("Load TTS Model")
|
| 238 |
tts_btn = gr.Button("EXPLODE AUDIO", variant="primary")
|
| 239 |
tts_pw = gr.Textbox(label="Password", type="password")
|
| 240 |
-
clear_tts_btn = gr.Button("Clear
|
| 241 |
with gr.Column():
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
clear_tts_btn.click(fn=clear_tts_model, inputs=tts_pw, outputs=tts_status_label)
|
| 248 |
|
| 249 |
if __name__ == "__main__":
|
| 250 |
demo.launch()
|
|
|
|
| 4 |
import torch
|
| 5 |
import re
|
| 6 |
import time
|
| 7 |
+
import gc
|
| 8 |
import soundfile as sf
|
| 9 |
from qwen_tts import Qwen3TTSModel
|
| 10 |
from langdetect import detect
|
|
|
|
| 12 |
|
| 13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 14 |
|
| 15 |
+
# --- Chat ---
|
| 16 |
chat_models = {
|
| 17 |
"Normal": "Qwen/Qwen3-0.6B",
|
| 18 |
"Thinking": "Qwen/Qwen2.5-1.5B-Instruct"
|
|
|
|
| 40 |
def chat_logic(user_input, mode):
|
| 41 |
model_id = chat_models[mode]
|
| 42 |
if model_id not in chat_model_loaded:
|
| 43 |
+
return "β Model Not Loaded"
|
|
|
|
| 44 |
model, tokenizer = loaded_chat_models[model_id], loaded_chat_tokenizers[model_id]
|
| 45 |
messages = [{"role": "user", "content": user_input}]
|
| 46 |
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 47 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
|
|
|
| 48 |
generated_ids = model.generate(**model_inputs, max_new_tokens=1024)
|
| 49 |
generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
|
| 50 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
|
|
|
| 51 |
cleaned_response = re.sub(r'<think>.*?</think>\s*\n?', '', response, flags=re.DOTALL)
|
| 52 |
return cleaned_response.strip()
|
| 53 |
|
|
|
|
| 58 |
del loaded_chat_models[model_id]
|
| 59 |
del loaded_chat_tokenizers[model_id]
|
| 60 |
chat_model_loaded.pop(model_id, None)
|
| 61 |
+
|
| 62 |
+
gc.collect()
|
| 63 |
torch.cuda.empty_cache()
|
| 64 |
+
if torch.cuda.is_available():
|
| 65 |
+
torch.cuda.ipc_collect()
|
| 66 |
+
return "π΄ Model Not Loaded (RAM Flushed)"
|
| 67 |
|
| 68 |
+
# --- Image ---
|
| 69 |
image_model_id = "stabilityai/sdxl-turbo"
|
| 70 |
image_pipe = None
|
| 71 |
image_model_loaded = False
|
|
|
|
| 73 |
def load_image_model():
|
| 74 |
global image_pipe, image_model_loaded
|
| 75 |
if image_pipe is None:
|
| 76 |
+
gr.Info("π‘ Priming TNT (Image Gen)...")
|
| 77 |
pipe = DiffusionPipeline.from_pretrained(
|
| 78 |
image_model_id,
|
| 79 |
torch_dtype=torch.float16 if device == "cuda" else torch.float32
|
|
|
|
| 88 |
if not image_model_loaded or image_pipe is None:
|
| 89 |
yield "β Model Not Loaded", None
|
| 90 |
return
|
|
|
|
| 91 |
start_time = time.time()
|
| 92 |
final_prompt = f"{prompt}, centered and realistic (if applicable)"
|
| 93 |
+
yield "π₯ IGNITING...", None
|
|
|
|
| 94 |
image = image_pipe(
|
| 95 |
prompt=final_prompt,
|
| 96 |
width=int(width),
|
|
|
|
| 99 |
guidance_scale=0.0,
|
| 100 |
output_type="pil"
|
| 101 |
).images[0]
|
|
|
|
| 102 |
duration = round(time.time() - start_time, 2)
|
| 103 |
yield f"π₯ EXPLODED in {duration}s", image
|
| 104 |
|
|
|
|
| 110 |
del image_pipe
|
| 111 |
image_pipe = None
|
| 112 |
image_model_loaded = False
|
| 113 |
+
gc.collect()
|
| 114 |
torch.cuda.empty_cache()
|
| 115 |
+
if torch.cuda.is_available():
|
| 116 |
+
torch.cuda.ipc_collect()
|
| 117 |
+
return "π΄ Model Not Loaded (RAM Flushed)"
|
| 118 |
|
| 119 |
+
# --- TTS ---
|
| 120 |
tts_model_id = "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice"
|
| 121 |
SUPPORTED_VOICES = ['aiden', 'dylan', 'eric', 'ono_anna', 'ryan', 'serena', 'sohee', 'uncle_fu', 'vivian']
|
| 122 |
tts_model = None
|
|
|
|
| 125 |
def load_tts_model():
|
| 126 |
global tts_model, tts_model_loaded
|
| 127 |
if tts_model is None:
|
| 128 |
+
gr.Info("π‘ Tuning Note-Blocks (TTS)...")
|
| 129 |
tts_model = Qwen3TTSModel.from_pretrained(
|
| 130 |
tts_model_id,
|
| 131 |
device_map=device,
|
|
|
|
| 139 |
if not tts_model_loaded or tts_model is None:
|
| 140 |
return None, "β Model Not Loaded"
|
| 141 |
try:
|
| 142 |
+
lang_map = {'zh': 'Chinese', 'en': 'English', 'jp': 'Japanese', 'ko': 'Korean'}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
detected_lang = "English"
|
| 144 |
if auto_detect:
|
| 145 |
try:
|
| 146 |
raw_lang = detect(text).split('-')[0]
|
| 147 |
detected_lang = lang_map.get(raw_lang, "English")
|
| 148 |
+
except: pass
|
|
|
|
|
|
|
| 149 |
wavs, sr = tts_model.generate_custom_voice(
|
| 150 |
+
language=detected_lang, speaker=voice, instruct=instructions, text=text
|
|
|
|
|
|
|
|
|
|
| 151 |
)
|
| 152 |
output_path = "creeper_voice.wav"
|
| 153 |
sf.write(output_path, wavs[0], sr)
|
| 154 |
+
return output_path, f"Speaker: {voice} | Lang: {detected_lang}"
|
| 155 |
except Exception as e:
|
| 156 |
+
return None, f"Error: {str(e)}"
|
| 157 |
|
| 158 |
def clear_tts_model(password):
|
| 159 |
global tts_model, tts_model_loaded
|
|
|
|
| 163 |
del tts_model
|
| 164 |
tts_model = None
|
| 165 |
tts_model_loaded = False
|
| 166 |
+
gc.collect()
|
| 167 |
torch.cuda.empty_cache()
|
| 168 |
+
if torch.cuda.is_available():
|
| 169 |
+
torch.cuda.ipc_collect()
|
| 170 |
+
return "π΄ Model Not Loaded (RAM Flushed)"
|
| 171 |
|
| 172 |
+
# --- UI ---
|
| 173 |
creeper_css = """
|
| 174 |
body { background-color: #000000; }
|
| 175 |
.gradio-container { background-color: #1e1e1e; border: 10px solid #2e8b57 !important; font-family: 'Courier New', Courier, monospace; color: #00ff00; }
|
| 176 |
footer { display: none !important; }
|
| 177 |
.gr-button-primary { background-color: #4A7023 !important; border: 4px solid #000 !important; color: white !important; font-weight: bold; text-transform: uppercase; }
|
|
|
|
| 178 |
label span { color: #2e8b57 !important; font-weight: bold; font-size: 1.2em; }
|
| 179 |
+
textarea, input, select, .gr-dropdown { background-color: #2e2e2e !important; color: #00ff00 !important; border: 3px solid #4A7023 !important; }
|
|
|
|
|
|
|
| 180 |
"""
|
| 181 |
|
| 182 |
with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
|
| 183 |
gr.Markdown("# π© CREEPER AI HUB π©")
|
|
|
|
| 184 |
with gr.Tabs():
|
| 185 |
with gr.TabItem("SSSSS-CHAT"):
|
| 186 |
+
chat_status = gr.Label("π΄ Model Not Loaded", label="Status")
|
|
|
|
| 187 |
with gr.Row():
|
| 188 |
+
mode_radio = gr.Radio(["Normal", "Thinking"], value="Normal", label="Mode")
|
| 189 |
+
load_chat_btn = gr.Button("Load Chat")
|
| 190 |
chat_pw = gr.Textbox(label="Password", type="password")
|
| 191 |
+
clear_chat_btn = gr.Button("Clear RAM")
|
| 192 |
+
chat_input = gr.Textbox(label="Message")
|
| 193 |
+
chat_output = gr.Textbox(label="Creeper Says")
|
| 194 |
+
chat_btn = gr.Button("EXPLODE TEXT", variant="primary")
|
| 195 |
+
load_chat_btn.click(load_chat_model, mode_radio, chat_status)
|
| 196 |
+
chat_btn.click(chat_logic, [chat_input, mode_radio], chat_output)
|
| 197 |
+
clear_chat_btn.click(clear_chat_model, chat_pw, chat_status)
|
|
|
|
|
|
|
| 198 |
|
| 199 |
with gr.TabItem("TNT-IMAGE"):
|
| 200 |
+
img_status = gr.Label("π΄ Model Not Loaded", label="Status")
|
|
|
|
| 201 |
with gr.Row():
|
| 202 |
+
with gr.Column():
|
| 203 |
+
img_prompt = gr.Textbox(label="Prompt")
|
| 204 |
+
w_s = gr.Slider(256, 1024, 512, step=64, label="Width")
|
| 205 |
+
h_s = gr.Slider(256, 1024, 512, step=64, label="Height")
|
| 206 |
+
s_s = gr.Slider(1, 10, 4, step=1, label="Steps")
|
| 207 |
+
load_img_btn = gr.Button("Load Image")
|
|
|
|
| 208 |
img_btn = gr.Button("EXPLODE IMAGE", variant="primary")
|
| 209 |
img_pw = gr.Textbox(label="Password", type="password")
|
| 210 |
+
clear_img_btn = gr.Button("Clear RAM")
|
| 211 |
+
img_out = gr.Image(label="Loot")
|
| 212 |
+
load_img_btn.click(load_image_model, None, img_status)
|
| 213 |
+
img_btn.click(image_logic, [img_prompt, w_s, h_s, s_s], [img_status, img_out])
|
| 214 |
+
clear_img_btn.click(clear_image_model, img_pw, img_status)
|
|
|
|
|
|
|
| 215 |
|
| 216 |
with gr.TabItem("NOTE-BLOCK (TTS)"):
|
| 217 |
+
tts_status = gr.Label("π΄ Model Not Loaded", label="Status")
|
|
|
|
| 218 |
with gr.Row():
|
| 219 |
with gr.Column():
|
| 220 |
+
tts_in = gr.Textbox(label="Text")
|
| 221 |
+
voice_sel = gr.Dropdown(SUPPORTED_VOICES, value="vivian", label="Voice")
|
| 222 |
+
auto_l = gr.Checkbox(True, label="Auto-detect")
|
| 223 |
+
style_in = gr.Textbox("Speak naturally", label="Style")
|
| 224 |
+
load_tts_btn = gr.Button("Load TTS")
|
|
|
|
| 225 |
tts_btn = gr.Button("EXPLODE AUDIO", variant="primary")
|
| 226 |
tts_pw = gr.Textbox(label="Password", type="password")
|
| 227 |
+
clear_tts_btn = gr.Button("Clear RAM")
|
| 228 |
with gr.Column():
|
| 229 |
+
aud_out = gr.Audio(label="Audio", type="filepath")
|
| 230 |
+
meta_out = gr.Label(label="Metadata")
|
| 231 |
+
load_tts_btn.click(load_tts_model, None, tts_status)
|
| 232 |
+
tts_btn.click(tts_logic, [tts_in, voice_sel, style_in, auto_l], [aud_out, meta_out])
|
| 233 |
+
clear_tts_btn.click(clear_tts_model, tts_pw, tts_status)
|
|
|
|
| 234 |
|
| 235 |
if __name__ == "__main__":
|
| 236 |
demo.launch()
|