Spaces:
Running
Running
CryptoCreeper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,8 +19,9 @@ chat_models = {
|
|
| 19 |
loaded_chat_models = {}
|
| 20 |
loaded_chat_tokenizers = {}
|
| 21 |
chat_status_label = None
|
|
|
|
| 22 |
|
| 23 |
-
def
|
| 24 |
global chat_status_label
|
| 25 |
model_id = chat_models[mode]
|
| 26 |
if model_id not in loaded_chat_models:
|
|
@@ -34,12 +35,16 @@ def get_chat_model(mode):
|
|
| 34 |
)
|
| 35 |
loaded_chat_models[model_id] = model
|
| 36 |
loaded_chat_tokenizers[model_id] = tokenizer
|
|
|
|
| 37 |
if chat_status_label:
|
| 38 |
chat_status_label.update("π’ Model Loaded")
|
| 39 |
-
return
|
| 40 |
|
| 41 |
def chat_logic(user_input, mode):
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
messages = [{"role": "user", "content": user_input}]
|
| 44 |
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 45 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
|
@@ -55,6 +60,7 @@ def clear_chat_model(password):
|
|
| 55 |
for model_id in list(loaded_chat_models.keys()):
|
| 56 |
del loaded_chat_models[model_id]
|
| 57 |
del loaded_chat_tokenizers[model_id]
|
|
|
|
| 58 |
torch.cuda.empty_cache()
|
| 59 |
if chat_status_label:
|
| 60 |
chat_status_label.update("π΄ Model Not Loaded")
|
|
@@ -64,9 +70,10 @@ def clear_chat_model(password):
|
|
| 64 |
image_model_id = "stabilityai/sdxl-turbo"
|
| 65 |
image_pipe = None
|
| 66 |
image_status_label = None
|
|
|
|
| 67 |
|
| 68 |
-
def
|
| 69 |
-
global image_pipe
|
| 70 |
if image_pipe is None:
|
| 71 |
if image_status_label:
|
| 72 |
image_status_label.update("π‘ Model Loading...")
|
|
@@ -76,16 +83,18 @@ def get_image_model():
|
|
| 76 |
)
|
| 77 |
pipe.to(device)
|
| 78 |
image_pipe = pipe
|
|
|
|
| 79 |
if image_status_label:
|
| 80 |
image_status_label.update("π’ Model Loaded")
|
| 81 |
-
return
|
| 82 |
|
| 83 |
def image_logic(prompt, width, height, steps):
|
| 84 |
-
|
|
|
|
| 85 |
start_time = time.time()
|
| 86 |
final_prompt = f"{prompt}, centered and realistic (if applicable)"
|
| 87 |
yield "π₯ IGNITING... (Image generator AI)...", None
|
| 88 |
-
image =
|
| 89 |
prompt=final_prompt,
|
| 90 |
width=int(width),
|
| 91 |
height=int(height),
|
|
@@ -98,12 +107,13 @@ def image_logic(prompt, width, height, steps):
|
|
| 98 |
yield f"π₯ EXPLODED in {duration}s", image
|
| 99 |
|
| 100 |
def clear_image_model(password):
|
| 101 |
-
global image_pipe
|
| 102 |
if password != "Creeper":
|
| 103 |
return "β Incorrect password"
|
| 104 |
if image_pipe:
|
| 105 |
del image_pipe
|
| 106 |
image_pipe = None
|
|
|
|
| 107 |
torch.cuda.empty_cache()
|
| 108 |
if image_status_label:
|
| 109 |
image_status_label.update("π΄ Model Not Loaded")
|
|
@@ -114,9 +124,10 @@ tts_model_id = "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice"
|
|
| 114 |
SUPPORTED_VOICES = ['aiden', 'dylan', 'eric', 'ono_anna', 'ryan', 'serena', 'sohee', 'uncle_fu', 'vivian']
|
| 115 |
tts_model = None
|
| 116 |
tts_status_label = None
|
|
|
|
| 117 |
|
| 118 |
-
def
|
| 119 |
-
global tts_model
|
| 120 |
if tts_model is None:
|
| 121 |
if tts_status_label:
|
| 122 |
tts_status_label.update("π‘ Model Loading...")
|
|
@@ -125,12 +136,14 @@ def get_tts_model():
|
|
| 125 |
device_map=device,
|
| 126 |
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32
|
| 127 |
)
|
|
|
|
| 128 |
if tts_status_label:
|
| 129 |
tts_status_label.update("π’ Model Loaded")
|
| 130 |
-
return
|
| 131 |
|
| 132 |
def tts_logic(text, voice, instructions, auto_detect):
|
| 133 |
-
|
|
|
|
| 134 |
try:
|
| 135 |
lang_map = {
|
| 136 |
'zh': 'Chinese', 'en': 'English', 'jp': 'Japanese',
|
|
@@ -144,7 +157,7 @@ def tts_logic(text, voice, instructions, auto_detect):
|
|
| 144 |
detected_lang = lang_map.get(raw_lang, "English")
|
| 145 |
except:
|
| 146 |
pass
|
| 147 |
-
wavs, sr =
|
| 148 |
language=detected_lang,
|
| 149 |
speaker=voice,
|
| 150 |
instruct=instructions,
|
|
@@ -157,12 +170,13 @@ def tts_logic(text, voice, instructions, auto_detect):
|
|
| 157 |
return None, f"System Error: {str(e)}"
|
| 158 |
|
| 159 |
def clear_tts_model(password):
|
| 160 |
-
global tts_model
|
| 161 |
if password != "Creeper":
|
| 162 |
return "β Incorrect password"
|
| 163 |
if tts_model:
|
| 164 |
del tts_model
|
| 165 |
tts_model = None
|
|
|
|
| 166 |
torch.cuda.empty_cache()
|
| 167 |
if tts_status_label:
|
| 168 |
tts_status_label.update("π΄ Model Not Loaded")
|
|
@@ -191,11 +205,13 @@ with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
|
|
| 191 |
chat_status_label = gr.Label("π΄ Model Not Loaded", label="Status")
|
| 192 |
with gr.Row():
|
| 193 |
mode_radio = gr.Radio(choices=["Normal", "Thinking"], value="Normal", label="Select Brain Mode")
|
|
|
|
| 194 |
clear_chat_btn = gr.Button("Clear Model (Password Protected)")
|
| 195 |
with gr.Column():
|
| 196 |
chat_input = gr.Textbox(lines=4, placeholder="Ssssss... Talk to the Creeper...", label="Message")
|
| 197 |
chat_output = gr.Textbox(label="Creeper Says")
|
| 198 |
chat_btn = gr.Button("EXPLODE TEXT", variant="primary")
|
|
|
|
| 199 |
chat_btn.click(fn=chat_logic, inputs=[chat_input, mode_radio], outputs=chat_output)
|
| 200 |
clear_chat_btn.click(fn=clear_chat_model, inputs=gr.Textbox(label="Enter Password"), outputs=chat_status_label)
|
| 201 |
|
|
@@ -210,10 +226,12 @@ with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
|
|
| 210 |
w_slider = gr.Slider(256, 768, 512, step=64, label="Block Width")
|
| 211 |
h_slider = gr.Slider(256, 768, 512, step=64, label="Block Height")
|
| 212 |
s_slider = gr.Slider(4, 12, 5, step=1, label="Detonation Steps")
|
|
|
|
| 213 |
img_btn = gr.Button("EXPLODE IMAGE", variant="primary")
|
| 214 |
clear_image_btn = gr.Button("Clear Model (Password Protected)")
|
| 215 |
with gr.Column(scale=1):
|
| 216 |
img_output = gr.Image(label="Rendered Loot")
|
|
|
|
| 217 |
img_btn.click(fn=image_logic, inputs=[img_prompt, w_slider, h_slider, s_slider], outputs=[image_status_label, img_output])
|
| 218 |
clear_image_btn.click(fn=clear_image_model, inputs=gr.Textbox(label="Enter Password"), outputs=image_status_label)
|
| 219 |
|
|
@@ -228,11 +246,13 @@ with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
|
|
| 228 |
voice_select = gr.Dropdown(choices=SUPPORTED_VOICES, value="vivian", label="Select Speaker")
|
| 229 |
auto_lang = gr.Checkbox(label="Auto-detect Language", value=True)
|
| 230 |
style_instruct = gr.Textbox(label="Style Instruction", value="Speak naturally")
|
|
|
|
| 231 |
tts_btn = gr.Button("EXPLODE AUDIO", variant="primary")
|
| 232 |
clear_tts_btn = gr.Button("Clear Model (Password Protected)")
|
| 233 |
with gr.Column():
|
| 234 |
audio_output = gr.Audio(label="Audio Output", type="filepath")
|
| 235 |
status_info = gr.Label(label="Block Metadata")
|
|
|
|
| 236 |
tts_btn.click(fn=tts_logic, inputs=[tts_input, voice_select, style_instruct, auto_lang], outputs=[audio_output, status_info])
|
| 237 |
clear_tts_btn.click(fn=clear_tts_model, inputs=gr.Textbox(label="Enter Password"), outputs=tts_status_label)
|
| 238 |
|
|
|
|
| 19 |
loaded_chat_models = {}
|
| 20 |
loaded_chat_tokenizers = {}
|
| 21 |
chat_status_label = None
|
| 22 |
+
chat_model_loaded = {}
|
| 23 |
|
| 24 |
+
def load_chat_model(mode):
|
| 25 |
global chat_status_label
|
| 26 |
model_id = chat_models[mode]
|
| 27 |
if model_id not in loaded_chat_models:
|
|
|
|
| 35 |
)
|
| 36 |
loaded_chat_models[model_id] = model
|
| 37 |
loaded_chat_tokenizers[model_id] = tokenizer
|
| 38 |
+
chat_model_loaded[model_id] = True
|
| 39 |
if chat_status_label:
|
| 40 |
chat_status_label.update("π’ Model Loaded")
|
| 41 |
+
return "β
Chat model loaded"
|
| 42 |
|
| 43 |
def chat_logic(user_input, mode):
|
| 44 |
+
model_id = chat_models[mode]
|
| 45 |
+
if model_id not in chat_model_loaded:
|
| 46 |
+
return "β Model Not Loaded"
|
| 47 |
+
model, tokenizer = loaded_chat_models[model_id], loaded_chat_tokenizers[model_id]
|
| 48 |
messages = [{"role": "user", "content": user_input}]
|
| 49 |
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 50 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
|
|
|
| 60 |
for model_id in list(loaded_chat_models.keys()):
|
| 61 |
del loaded_chat_models[model_id]
|
| 62 |
del loaded_chat_tokenizers[model_id]
|
| 63 |
+
chat_model_loaded.pop(model_id, None)
|
| 64 |
torch.cuda.empty_cache()
|
| 65 |
if chat_status_label:
|
| 66 |
chat_status_label.update("π΄ Model Not Loaded")
|
|
|
|
| 70 |
image_model_id = "stabilityai/sdxl-turbo"
|
| 71 |
image_pipe = None
|
| 72 |
image_status_label = None
|
| 73 |
+
image_model_loaded = False
|
| 74 |
|
| 75 |
+
def load_image_model():
|
| 76 |
+
global image_pipe, image_model_loaded
|
| 77 |
if image_pipe is None:
|
| 78 |
if image_status_label:
|
| 79 |
image_status_label.update("π‘ Model Loading...")
|
|
|
|
| 83 |
)
|
| 84 |
pipe.to(device)
|
| 85 |
image_pipe = pipe
|
| 86 |
+
image_model_loaded = True
|
| 87 |
if image_status_label:
|
| 88 |
image_status_label.update("π’ Model Loaded")
|
| 89 |
+
return "β
Image model loaded"
|
| 90 |
|
| 91 |
def image_logic(prompt, width, height, steps):
|
| 92 |
+
if not image_model_loaded or image_pipe is None:
|
| 93 |
+
return "β Model Not Loaded", None
|
| 94 |
start_time = time.time()
|
| 95 |
final_prompt = f"{prompt}, centered and realistic (if applicable)"
|
| 96 |
yield "π₯ IGNITING... (Image generator AI)...", None
|
| 97 |
+
image = image_pipe(
|
| 98 |
prompt=final_prompt,
|
| 99 |
width=int(width),
|
| 100 |
height=int(height),
|
|
|
|
| 107 |
yield f"π₯ EXPLODED in {duration}s", image
|
| 108 |
|
| 109 |
def clear_image_model(password):
|
| 110 |
+
global image_pipe, image_model_loaded
|
| 111 |
if password != "Creeper":
|
| 112 |
return "β Incorrect password"
|
| 113 |
if image_pipe:
|
| 114 |
del image_pipe
|
| 115 |
image_pipe = None
|
| 116 |
+
image_model_loaded = False
|
| 117 |
torch.cuda.empty_cache()
|
| 118 |
if image_status_label:
|
| 119 |
image_status_label.update("π΄ Model Not Loaded")
|
|
|
|
| 124 |
SUPPORTED_VOICES = ['aiden', 'dylan', 'eric', 'ono_anna', 'ryan', 'serena', 'sohee', 'uncle_fu', 'vivian']
|
| 125 |
tts_model = None
|
| 126 |
tts_status_label = None
|
| 127 |
+
tts_model_loaded = False
|
| 128 |
|
| 129 |
+
def load_tts_model():
|
| 130 |
+
global tts_model, tts_model_loaded
|
| 131 |
if tts_model is None:
|
| 132 |
if tts_status_label:
|
| 133 |
tts_status_label.update("π‘ Model Loading...")
|
|
|
|
| 136 |
device_map=device,
|
| 137 |
torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32
|
| 138 |
)
|
| 139 |
+
tts_model_loaded = True
|
| 140 |
if tts_status_label:
|
| 141 |
tts_status_label.update("π’ Model Loaded")
|
| 142 |
+
return "β
TTS model loaded"
|
| 143 |
|
| 144 |
def tts_logic(text, voice, instructions, auto_detect):
|
| 145 |
+
if not tts_model_loaded or tts_model is None:
|
| 146 |
+
return None, "β Model Not Loaded"
|
| 147 |
try:
|
| 148 |
lang_map = {
|
| 149 |
'zh': 'Chinese', 'en': 'English', 'jp': 'Japanese',
|
|
|
|
| 157 |
detected_lang = lang_map.get(raw_lang, "English")
|
| 158 |
except:
|
| 159 |
pass
|
| 160 |
+
wavs, sr = tts_model.generate_custom_voice(
|
| 161 |
language=detected_lang,
|
| 162 |
speaker=voice,
|
| 163 |
instruct=instructions,
|
|
|
|
| 170 |
return None, f"System Error: {str(e)}"
|
| 171 |
|
| 172 |
def clear_tts_model(password):
|
| 173 |
+
global tts_model, tts_model_loaded
|
| 174 |
if password != "Creeper":
|
| 175 |
return "β Incorrect password"
|
| 176 |
if tts_model:
|
| 177 |
del tts_model
|
| 178 |
tts_model = None
|
| 179 |
+
tts_model_loaded = False
|
| 180 |
torch.cuda.empty_cache()
|
| 181 |
if tts_status_label:
|
| 182 |
tts_status_label.update("π΄ Model Not Loaded")
|
|
|
|
| 205 |
chat_status_label = gr.Label("π΄ Model Not Loaded", label="Status")
|
| 206 |
with gr.Row():
|
| 207 |
mode_radio = gr.Radio(choices=["Normal", "Thinking"], value="Normal", label="Select Brain Mode")
|
| 208 |
+
load_chat_btn = gr.Button("Load Chat Model")
|
| 209 |
clear_chat_btn = gr.Button("Clear Model (Password Protected)")
|
| 210 |
with gr.Column():
|
| 211 |
chat_input = gr.Textbox(lines=4, placeholder="Ssssss... Talk to the Creeper...", label="Message")
|
| 212 |
chat_output = gr.Textbox(label="Creeper Says")
|
| 213 |
chat_btn = gr.Button("EXPLODE TEXT", variant="primary")
|
| 214 |
+
load_chat_btn.click(fn=load_chat_model, inputs=mode_radio, outputs=chat_status_label)
|
| 215 |
chat_btn.click(fn=chat_logic, inputs=[chat_input, mode_radio], outputs=chat_output)
|
| 216 |
clear_chat_btn.click(fn=clear_chat_model, inputs=gr.Textbox(label="Enter Password"), outputs=chat_status_label)
|
| 217 |
|
|
|
|
| 226 |
w_slider = gr.Slider(256, 768, 512, step=64, label="Block Width")
|
| 227 |
h_slider = gr.Slider(256, 768, 512, step=64, label="Block Height")
|
| 228 |
s_slider = gr.Slider(4, 12, 5, step=1, label="Detonation Steps")
|
| 229 |
+
load_image_btn = gr.Button("Load Image Model")
|
| 230 |
img_btn = gr.Button("EXPLODE IMAGE", variant="primary")
|
| 231 |
clear_image_btn = gr.Button("Clear Model (Password Protected)")
|
| 232 |
with gr.Column(scale=1):
|
| 233 |
img_output = gr.Image(label="Rendered Loot")
|
| 234 |
+
load_image_btn.click(fn=load_image_model, inputs=None, outputs=image_status_label)
|
| 235 |
img_btn.click(fn=image_logic, inputs=[img_prompt, w_slider, h_slider, s_slider], outputs=[image_status_label, img_output])
|
| 236 |
clear_image_btn.click(fn=clear_image_model, inputs=gr.Textbox(label="Enter Password"), outputs=image_status_label)
|
| 237 |
|
|
|
|
| 246 |
voice_select = gr.Dropdown(choices=SUPPORTED_VOICES, value="vivian", label="Select Speaker")
|
| 247 |
auto_lang = gr.Checkbox(label="Auto-detect Language", value=True)
|
| 248 |
style_instruct = gr.Textbox(label="Style Instruction", value="Speak naturally")
|
| 249 |
+
load_tts_btn = gr.Button("Load TTS Model")
|
| 250 |
tts_btn = gr.Button("EXPLODE AUDIO", variant="primary")
|
| 251 |
clear_tts_btn = gr.Button("Clear Model (Password Protected)")
|
| 252 |
with gr.Column():
|
| 253 |
audio_output = gr.Audio(label="Audio Output", type="filepath")
|
| 254 |
status_info = gr.Label(label="Block Metadata")
|
| 255 |
+
load_tts_btn.click(fn=load_tts_model, inputs=None, outputs=tts_status_label)
|
| 256 |
tts_btn.click(fn=tts_logic, inputs=[tts_input, voice_select, style_instruct, auto_lang], outputs=[audio_output, status_info])
|
| 257 |
clear_tts_btn.click(fn=clear_tts_model, inputs=gr.Textbox(label="Enter Password"), outputs=tts_status_label)
|
| 258 |
|