CryptoCreeper commited on
Commit
d4fabb4
Β·
verified Β·
1 Parent(s): 9d846ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -23
app.py CHANGED
@@ -11,29 +11,21 @@ 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"
17
  }
18
-
19
  loaded_chat_models = {}
20
  loaded_chat_tokenizers = {}
21
-
22
- image_model_id = "stabilityai/sdxl-turbo"
23
- image_pipe = DiffusionPipeline.from_pretrained(image_model_id)
24
- image_pipe.to(device)
25
-
26
- tts_model_id = "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice"
27
- SUPPORTED_VOICES = ['aiden', 'dylan', 'eric', 'ono_anna', 'ryan', 'serena', 'sohee', 'uncle_fu', 'vivian']
28
- tts_model = Qwen3TTSModel.from_pretrained(
29
- tts_model_id,
30
- device_map=device,
31
- torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32
32
- )
33
 
34
  def get_chat_model(mode):
 
35
  model_id = chat_models[mode]
36
  if model_id not in loaded_chat_models:
 
 
37
  tokenizer = AutoTokenizer.from_pretrained(model_id)
38
  model = AutoModelForCausalLM.from_pretrained(
39
  model_id,
@@ -42,6 +34,8 @@ def get_chat_model(mode):
42
  )
43
  loaded_chat_models[model_id] = model
44
  loaded_chat_tokenizers[model_id] = tokenizer
 
 
45
  return loaded_chat_models[model_id], loaded_chat_tokenizers[model_id]
46
 
47
  def chat_logic(user_input, mode):
@@ -55,11 +49,43 @@ def chat_logic(user_input, mode):
55
  cleaned_response = re.sub(r'<think>.*?</think>\s*\n?', '', response, flags=re.DOTALL)
56
  return cleaned_response.strip()
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  def image_logic(prompt, width, height, steps):
 
59
  start_time = time.time()
60
  final_prompt = f"{prompt}, centered and realistic (if applicable)"
61
  yield "πŸ’₯ IGNITING... (Image generator AI)...", None
62
- image = image_pipe(
63
  prompt=final_prompt,
64
  width=int(width),
65
  height=int(height),
@@ -71,21 +97,54 @@ def image_logic(prompt, width, height, steps):
71
  duration = round(time.time() - start_time, 2)
72
  yield f"πŸ’₯ EXPLODED in {duration}s", image
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  def tts_logic(text, voice, instructions, auto_detect):
 
75
  try:
76
  lang_map = {
77
- 'zh': 'Chinese', 'en': 'English', 'jp': 'Japanese',
78
- 'ko': 'Korean', 'de': 'German', 'fr': 'French',
79
  'ru': 'Russian', 'pt': 'Portuguese', 'es': 'Spanish', 'it': 'Italian'
80
  }
81
- detected_lang = "English"
82
  if auto_detect:
83
  try:
84
  raw_lang = detect(text).split('-')[0]
85
  detected_lang = lang_map.get(raw_lang, "English")
86
  except:
87
  pass
88
- wavs, sr = tts_model.generate_custom_voice(
89
  language=detected_lang,
90
  speaker=voice,
91
  instruct=instructions,
@@ -97,6 +156,19 @@ def tts_logic(text, voice, instructions, auto_detect):
97
  except Exception as e:
98
  return None, f"System Error: {str(e)}"
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  creeper_css = """
101
  body { background-color: #000000; }
102
  .gradio-container { background-color: #1e1e1e; border: 10px solid #2e8b57 !important; font-family: 'Courier New', Courier, monospace; color: #00ff00; }
@@ -111,20 +183,26 @@ textarea, input, .gr-box, .gr-input, select, .gr-dropdown { background-color: #2
111
 
112
  with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
113
  gr.Markdown("# 🟩 CREEPER AI HUB 🟩")
114
-
115
  with gr.Tabs():
 
116
  with gr.TabItem("SSSSS-CHAT"):
117
  gr.Markdown("### Qwen Chat System")
 
118
  with gr.Row():
119
  mode_radio = gr.Radio(choices=["Normal", "Thinking"], value="Normal", label="Select Brain Mode")
 
120
  with gr.Column():
121
  chat_input = gr.Textbox(lines=4, placeholder="Ssssss... Talk to the Creeper...", label="Message")
122
  chat_output = gr.Textbox(label="Creeper Says")
123
  chat_btn = gr.Button("EXPLODE TEXT", variant="primary")
124
  chat_btn.click(fn=chat_logic, inputs=[chat_input, mode_radio], outputs=chat_output)
125
-
 
 
126
  with gr.TabItem("TNT-IMAGE"):
127
  gr.Markdown("### Image Generator System")
 
128
  with gr.Row():
129
  with gr.Column(scale=1):
130
  img_prompt = gr.Textbox(label="Visual Idea", placeholder="A pixelated forest...", lines=3)
@@ -133,13 +211,16 @@ with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
133
  h_slider = gr.Slider(256, 768, 512, step=64, label="Block Height")
134
  s_slider = gr.Slider(4, 12, 5, step=1, label="Detonation Steps")
135
  img_btn = gr.Button("EXPLODE IMAGE", variant="primary")
 
136
  with gr.Column(scale=1):
137
- img_status = gr.Markdown("### Status: 🟒 Armed")
138
  img_output = gr.Image(label="Rendered Loot")
139
- img_btn.click(fn=image_logic, inputs=[img_prompt, w_slider, h_slider, s_slider], outputs=[img_status, img_output])
 
140
 
 
141
  with gr.TabItem("NOTE-BLOCK (TTS)"):
142
  gr.Markdown("### Smart Audio Studio")
 
143
  with gr.Row():
144
  with gr.Column():
145
  tts_input = gr.Textbox(label="Text to Speak", placeholder="Enter text for the block to play...", lines=4)
@@ -148,10 +229,12 @@ with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
148
  auto_lang = gr.Checkbox(label="Auto-detect Language", value=True)
149
  style_instruct = gr.Textbox(label="Style Instruction", value="Speak naturally")
150
  tts_btn = gr.Button("EXPLODE AUDIO", variant="primary")
 
151
  with gr.Column():
152
  audio_output = gr.Audio(label="Audio Output", type="filepath")
153
  status_info = gr.Label(label="Block Metadata")
154
  tts_btn.click(fn=tts_logic, inputs=[tts_input, voice_select, style_instruct, auto_lang], outputs=[audio_output, status_info])
 
155
 
156
  if __name__ == "__main__":
157
- demo.launch()
 
11
 
12
  device = "cuda" if torch.cuda.is_available() else "cpu"
13
 
14
+ # --- Chat ---
15
  chat_models = {
16
  "Normal": "Qwen/Qwen3-0.6B",
17
  "Thinking": "Qwen/Qwen2.5-1.5B-Instruct"
18
  }
 
19
  loaded_chat_models = {}
20
  loaded_chat_tokenizers = {}
21
+ chat_status_label = None
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  def get_chat_model(mode):
24
+ global chat_status_label
25
  model_id = chat_models[mode]
26
  if model_id not in loaded_chat_models:
27
+ if chat_status_label:
28
+ chat_status_label.update("🟑 Model Loading...")
29
  tokenizer = AutoTokenizer.from_pretrained(model_id)
30
  model = AutoModelForCausalLM.from_pretrained(
31
  model_id,
 
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 loaded_chat_models[model_id], loaded_chat_tokenizers[model_id]
40
 
41
  def chat_logic(user_input, mode):
 
49
  cleaned_response = re.sub(r'<think>.*?</think>\s*\n?', '', response, flags=re.DOTALL)
50
  return cleaned_response.strip()
51
 
52
+ def clear_chat_model(password):
53
+ if password != "Creeper":
54
+ return "❌ Incorrect 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")
61
+ return "βœ… Chat model cleared from RAM"
62
+
63
+ # --- Image ---
64
+ image_model_id = "stabilityai/sdxl-turbo"
65
+ image_pipe = None
66
+ image_status_label = None
67
+
68
+ def get_image_model():
69
+ global image_pipe
70
+ if image_pipe is None:
71
+ if image_status_label:
72
+ image_status_label.update("🟑 Model Loading...")
73
+ pipe = DiffusionPipeline.from_pretrained(
74
+ image_model_id,
75
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32
76
+ )
77
+ pipe.to(device)
78
+ image_pipe = pipe
79
+ if image_status_label:
80
+ image_status_label.update("🟒 Model Loaded")
81
+ return image_pipe
82
+
83
  def image_logic(prompt, width, height, steps):
84
+ pipe = get_image_model()
85
  start_time = time.time()
86
  final_prompt = f"{prompt}, centered and realistic (if applicable)"
87
  yield "πŸ’₯ IGNITING... (Image generator AI)...", None
88
+ image = pipe(
89
  prompt=final_prompt,
90
  width=int(width),
91
  height=int(height),
 
97
  duration = round(time.time() - start_time, 2)
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")
110
+ return "βœ… Image model cleared from RAM"
111
+
112
+ # --- TTS ---
113
+ 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 get_tts_model():
119
+ global tts_model
120
+ if tts_model is None:
121
+ if tts_status_label:
122
+ tts_status_label.update("🟑 Model Loading...")
123
+ tts_model = Qwen3TTSModel.from_pretrained(
124
+ tts_model_id,
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 tts_model
131
+
132
  def tts_logic(text, voice, instructions, auto_detect):
133
+ model = get_tts_model()
134
  try:
135
  lang_map = {
136
+ 'zh': 'Chinese', 'en': 'English', 'jp': 'Japanese',
137
+ 'ko': 'Korean', 'de': 'German', 'fr': 'French',
138
  'ru': 'Russian', 'pt': 'Portuguese', 'es': 'Spanish', 'it': 'Italian'
139
  }
140
+ detected_lang = "English"
141
  if auto_detect:
142
  try:
143
  raw_lang = detect(text).split('-')[0]
144
  detected_lang = lang_map.get(raw_lang, "English")
145
  except:
146
  pass
147
+ wavs, sr = model.generate_custom_voice(
148
  language=detected_lang,
149
  speaker=voice,
150
  instruct=instructions,
 
156
  except Exception as e:
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")
169
+ return "βœ… TTS model cleared from RAM"
170
+
171
+ # --- UI ---
172
  creeper_css = """
173
  body { background-color: #000000; }
174
  .gradio-container { background-color: #1e1e1e; border: 10px solid #2e8b57 !important; font-family: 'Courier New', Courier, monospace; color: #00ff00; }
 
183
 
184
  with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
185
  gr.Markdown("# 🟩 CREEPER AI HUB 🟩")
186
+
187
  with gr.Tabs():
188
+ # --- Chat ---
189
  with gr.TabItem("SSSSS-CHAT"):
190
  gr.Markdown("### Qwen Chat System")
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
+
202
+ # --- Image ---
203
  with gr.TabItem("TNT-IMAGE"):
204
  gr.Markdown("### Image Generator System")
205
+ image_status_label = gr.Label("πŸ”΄ Model Not Loaded", label="Status")
206
  with gr.Row():
207
  with gr.Column(scale=1):
208
  img_prompt = gr.Textbox(label="Visual Idea", placeholder="A pixelated forest...", lines=3)
 
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
 
220
+ # --- TTS ---
221
  with gr.TabItem("NOTE-BLOCK (TTS)"):
222
  gr.Markdown("### Smart Audio Studio")
223
+ tts_status_label = gr.Label("πŸ”΄ Model Not Loaded", label="Status")
224
  with gr.Row():
225
  with gr.Column():
226
  tts_input = gr.Textbox(label="Text to Speak", placeholder="Enter text for the block to play...", lines=4)
 
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
 
239
  if __name__ == "__main__":
240
+ demo.launch()