CryptoCreeper commited on
Commit
df3c6eb
·
verified ·
1 Parent(s): 7a83adb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -13
app.py CHANGED
@@ -4,33 +4,45 @@ from diffusers import DiffusionPipeline
4
  import torch
5
  import re
6
  import time
 
 
 
 
7
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
 
10
- models = {
11
  "Normal": "Qwen/Qwen3-0.6B",
12
  "Thinking": "Qwen/Qwen2.5-1.5B-Instruct"
13
  }
14
 
15
- loaded_models = {}
16
- loaded_tokenizers = {}
17
 
18
  image_model_id = "SimianLuo/LCM_Dreamshaper_v7"
19
  image_pipe = DiffusionPipeline.from_pretrained(image_model_id)
20
  image_pipe.to(device)
21
 
 
 
 
 
 
 
 
 
22
  def get_chat_model(mode):
23
- model_id = models[mode]
24
- if model_id not in loaded_models:
25
  tokenizer = AutoTokenizer.from_pretrained(model_id)
26
  model = AutoModelForCausalLM.from_pretrained(
27
  model_id,
28
  torch_dtype="auto",
29
  device_map="auto"
30
  )
31
- loaded_models[model_id] = model
32
- loaded_tokenizers[model_id] = tokenizer
33
- return loaded_models[model_id], loaded_tokenizers[model_id]
34
 
35
  def chat_logic(user_input, mode):
36
  model, tokenizer = get_chat_model(mode)
@@ -47,7 +59,6 @@ def image_logic(prompt, width, height, steps):
47
  start_time = time.time()
48
  final_prompt = f"{prompt}, centered and realistic (if applicable)"
49
  yield "💥 IGNITING... (Image generator AI)...", None
50
-
51
  image = image_pipe(
52
  prompt=final_prompt,
53
  width=int(width),
@@ -57,10 +68,35 @@ def image_logic(prompt, width, height, steps):
57
  lcm_origin_steps=50,
58
  output_type="pil"
59
  ).images[0]
60
-
61
  duration = round(time.time() - start_time, 2)
62
  yield f"💥 EXPLODED in {duration}s", image
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  creeper_css = """
65
  body { background-color: #000000; }
66
  .gradio-container { background-color: #1e1e1e; border: 10px solid #2e8b57 !important; font-family: 'Courier New', Courier, monospace; color: #00ff00; }
@@ -68,7 +104,7 @@ footer { display: none !important; }
68
  .gr-button-primary { background-color: #4A7023 !important; border: 4px solid #000 !important; color: white !important; font-weight: bold; text-transform: uppercase; }
69
  .gr-button-primary:hover { background-color: #5ea032 !important; box-shadow: 0 0 20px #2e8b57; }
70
  label span { color: #2e8b57 !important; font-weight: bold; font-size: 1.2em; }
71
- textarea, input, .gr-box, .gr-input { background-color: #2e2e2e !important; color: #00ff00 !important; border: 3px solid #4A7023 !important; }
72
  .tabs { border-bottom: 5px solid #4A7023 !important; }
73
  .tab-nav button.selected { background-color: #4A7023 !important; color: white !important; }
74
  """
@@ -85,7 +121,6 @@ with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
85
  chat_input = gr.Textbox(lines=4, placeholder="Ssssss... Talk to the Creeper...", label="Message")
86
  chat_output = gr.Textbox(label="Creeper Says")
87
  chat_btn = gr.Button("EXPLODE TEXT", variant="primary")
88
-
89
  chat_btn.click(fn=chat_logic, inputs=[chat_input, mode_radio], outputs=chat_output)
90
 
91
  with gr.TabItem("TNT-IMAGE"):
@@ -101,8 +136,22 @@ with gr.Blocks(css=creeper_css, title="CREEPER AI HUB") as demo:
101
  with gr.Column(scale=1):
102
  img_status = gr.Markdown("### Status: 🟢 Armed")
103
  img_output = gr.Image(label="Rendered Loot")
104
-
105
  img_btn.click(fn=image_logic, inputs=[img_prompt, w_slider, h_slider, s_slider], outputs=[img_status, img_output])
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  if __name__ == "__main__":
108
  demo.launch()
 
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
10
+ 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 = "SimianLuo/LCM_Dreamshaper_v7"
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,
40
  torch_dtype="auto",
41
  device_map="auto"
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):
48
  model, tokenizer = get_chat_model(mode)
 
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),
 
68
  lcm_origin_steps=50,
69
  output_type="pil"
70
  ).images[0]
 
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,
92
+ text=text
93
+ )
94
+ output_path = "creeper_voice.wav"
95
+ sf.write(output_path, wavs[0], sr)
96
+ return output_path, f"Language: {detected_lang} | Speaker: {voice}"
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; }
 
104
  .gr-button-primary { background-color: #4A7023 !important; border: 4px solid #000 !important; color: white !important; font-weight: bold; text-transform: uppercase; }
105
  .gr-button-primary:hover { background-color: #5ea032 !important; box-shadow: 0 0 20px #2e8b57; }
106
  label span { color: #2e8b57 !important; font-weight: bold; font-size: 1.2em; }
107
+ textarea, input, .gr-box, .gr-input, select, .gr-dropdown { background-color: #2e2e2e !important; color: #00ff00 !important; border: 3px solid #4A7023 !important; }
108
  .tabs { border-bottom: 5px solid #4A7023 !important; }
109
  .tab-nav button.selected { background-color: #4A7023 !important; color: white !important; }
110
  """
 
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"):
 
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)
146
+ with gr.Row():
147
+ voice_select = gr.Dropdown(choices=SUPPORTED_VOICES, value="vivian", label="Select Speaker")
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()