Novix commited on
Commit
26580a6
·
verified ·
1 Parent(s): ce661cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -43
app.py CHANGED
@@ -11,21 +11,11 @@ import soundfile as sf
11
  import numpy as np
12
  import tempfile
13
 
14
- from download import download_model
15
-
16
- # 🎯 خطوة السيادة الأولى: توجيه المحرك لتحميل أوزانكِ الخاصة بدلاً من المستودع العام
17
  APP_DIR = op.dirname(op.abspath(__file__))
18
- MODEL_ID = "Novix/SongGenerationtwo" # مستودع أوزانكِ السيادية
19
-
20
- print(f"⏳ [Novix Core] جاري سحب الأوزان السيادية من المستودع: {MODEL_ID}...")
21
- try:
22
- # تحميل الأوزان مباشرة إلى البيئة المحلية للـ Space
23
- download_model(APP_DIR, repo_id=MODEL_ID, revision="main")
24
- print("✅ تم تحميل الأوزان السيادية لـ Novix بنجاح.")
25
- except Exception as e:
26
- print(f"⚠️ تنبيه أثناء تحميل الأوزان: {e}. سيتم الاعتماد على الأوزان المحلية إن وجدت.")
27
 
28
- # تهيئة وإقلاع المحرك من الفئة الأصلية المستقرة
29
  from levo_inference import LeVoInference
30
  MODEL = None
31
 
@@ -64,20 +54,19 @@ def save_as_flac(sample_rate, audio_data):
64
  sf.write(temp_file, audio_data, sample_rate, format='FLAC')
65
  return temp_file.name
66
 
67
- # دالة التوليد الأصلية بعد ربطها بـ Novix Core
68
  def generate_song(lyric, description=None, prompt_audio=None, genre=None, cfg_coef=None, temperature=0.1, top_k=-1, gen_type="mixed", progress=gr.Progress(track_tqdm=True)):
69
  global MODEL
70
  global STRUCTS
71
 
72
  if MODEL is None:
73
- return None, json.dumps({"error": "المحرك لم يتم تحميله في الذاكرة بعد. يرجى إعادة تحديث الصفحة أو مراجعة السجلات."})
74
 
75
  params = {'cfg_coef': cfg_coef, 'temperature': temperature, 'top_k': top_k}
76
  params = {k: v for k, v in params.items() if v is not None}
77
  vocal_structs = ['[verse]', '[chorus]', '[bridge]']
78
  sample_rate = MODEL.cfg.sample_rate
79
 
80
- # تنسيق وتطهير الكلمات والمقاطع الهيكلية
81
  lyric = lyric.replace("[intro]", "[intro-short]").replace("[inst]", "[inst-short]").replace("[outro]", "[outro-short]")
82
  paragraphs = [p.strip() for p in lyric.strip().split('\n\n') if p.strip()]
83
 
@@ -123,10 +112,9 @@ def generate_song(lyric, description=None, prompt_audio=None, genre=None, cfg_co
123
  if description[-1] != ".":
124
  description = description + "."
125
 
126
- progress(0.0, "⚡ [Novix Core] التوليد مستمر الآن...")
127
  start = time.time()
128
 
129
- # تشغيل المصفوفات الحقيقية للأوزان المستقلة
130
  prompt_path = op.join(APP_DIR, "tools/new_prompt.pt")
131
  audio_data = MODEL(lyric_norm, description, prompt_audio, genre, prompt_path, gen_type, params).cpu().permute(1, 0).float().numpy()
132
 
@@ -140,27 +128,21 @@ def generate_song(lyric, description=None, prompt_audio=None, genre=None, cfg_co
140
  "params": params,
141
  "inference_duration": end - start,
142
  "timestamp": datetime.now().isoformat(),
143
- "engine": "Novix Sovereign Studio (Independent Mode)"
144
  }
145
 
146
  filepath = save_as_flac(sample_rate, audio_data)
147
  return filepath, json.dumps(input_config, indent=2)
148
 
149
 
150
- # بناء الواجهة الاحترافية الكبرى لـ Gradio
151
  with gr.Blocks(title="Novix Sovereign Studio Pro") as demo:
152
  gr.Markdown("# 🎵 استوديو Novix المستقل والمملوك لك بالكامل 100%")
153
- gr.Markdown("🛡️ تم فك الارتباط من خوادم الشركات وتوجيه النواة لأوزانكِ الخاصة للإنتاج والربح الحر.")
154
 
155
  with gr.Row():
156
  with gr.Column():
157
- lyric = gr.Textbox(
158
- label="Lyrics",
159
- lines=5,
160
- max_lines=15,
161
- value=EXAMPLE_LYRICS,
162
- info="قوالب المقاطع الصوتية المدعومة: [intro], [verse], [chorus], [bridge], [inst], [outro]"
163
- )
164
 
165
  with gr.Tabs(elem_id="extra-tabs"):
166
  with gr.Tab("Genre Select"):
@@ -171,18 +153,9 @@ with gr.Blocks(title="Novix Sovereign Studio Pro") as demo:
171
  interactive=True
172
  )
173
  with gr.Tab("Text Prompt"):
174
- description = gr.Textbox(
175
- label="Song Description (Optional)",
176
- info="اكتبي مواصفات الصوت بالأرقام أو الإنجليزية (مثال: female, sad pop, piano).",
177
- placeholder="female, rock, motivational, electric guitar, bass guitar, drum kit.",
178
- lines=1,
179
- max_lines=2
180
- )
181
  with gr.Tab("Audio Prompt"):
182
- prompt_audio = gr.Audio(
183
- label="Prompt Audio (Optional)",
184
- type="filepath"
185
- )
186
 
187
  with gr.Accordion("Advanced Config", open=False):
188
  cfg_coef = gr.Slider(label="CFG Coefficient", minimum=0.1, maximum=3.0, step=0.1, value=1.8, interactive=True)
@@ -201,17 +174,15 @@ with gr.Blocks(title="Novix Sovereign Studio Pro") as demo:
201
  outputs=[output_audio, output_json]
202
  )
203
 
204
- # تشغيل الإقلاع المستقل للنواة
205
  if __name__ == "__main__":
206
  torch.set_num_threads(1)
207
  ckpt_path = op.join(APP_DIR, "ckpt")
208
 
209
- # التأكد من وجود مجلد الأوزان وإقلاع النموذج فوراً
210
  if not op.exists(ckpt_path):
211
  os.makedirs(ckpt_path, exist_ok=True)
212
 
213
- print("🧠 جاري صهر وبناء بيئة الاستدلال الصوتي المستقل...")
214
  MODEL = LeVoInference(ckpt_path)
215
- print("✅ النصر الكلي! الاستوديو شغال أوفلاين وجاهز لاستقبال ضربة زر التوليد.")
216
 
217
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
11
  import numpy as np
12
  import tempfile
13
 
14
+ # 🦾 تم بتر سطر الـ download المكسور كلياً لأن الأوزان سيادية وموجودة محلياً بالفعل
 
 
15
  APP_DIR = op.dirname(op.abspath(__file__))
16
+ MODEL_ID = "Novix/SongGenerationtwo" # مستودع أوزانكِ
 
 
 
 
 
 
 
 
17
 
18
+ # تهيئة وإقلاع المحرك من الفئة الأصلية للمستودع
19
  from levo_inference import LeVoInference
20
  MODEL = None
21
 
 
54
  sf.write(temp_file, audio_data, sample_rate, format='FLAC')
55
  return temp_file.name
56
 
57
+ # دالة التوليد القياسية لـ Novix
58
  def generate_song(lyric, description=None, prompt_audio=None, genre=None, cfg_coef=None, temperature=0.1, top_k=-1, gen_type="mixed", progress=gr.Progress(track_tqdm=True)):
59
  global MODEL
60
  global STRUCTS
61
 
62
  if MODEL is None:
63
+ return None, json.dumps({"error": "المحرك لم يتم تحميله في الذاكرة بعد."})
64
 
65
  params = {'cfg_coef': cfg_coef, 'temperature': temperature, 'top_k': top_k}
66
  params = {k: v for k, v in params.items() if v is not None}
67
  vocal_structs = ['[verse]', '[chorus]', '[bridge]']
68
  sample_rate = MODEL.cfg.sample_rate
69
 
 
70
  lyric = lyric.replace("[intro]", "[intro-short]").replace("[inst]", "[inst-short]").replace("[outro]", "[outro-short]")
71
  paragraphs = [p.strip() for p in lyric.strip().split('\n\n') if p.strip()]
72
 
 
112
  if description[-1] != ".":
113
  description = description + "."
114
 
115
+ progress(0.0, "⚡ [Novix Core] جاري التوليد المحلي الآن...")
116
  start = time.time()
117
 
 
118
  prompt_path = op.join(APP_DIR, "tools/new_prompt.pt")
119
  audio_data = MODEL(lyric_norm, description, prompt_audio, genre, prompt_path, gen_type, params).cpu().permute(1, 0).float().numpy()
120
 
 
128
  "params": params,
129
  "inference_duration": end - start,
130
  "timestamp": datetime.now().isoformat(),
131
+ "engine": "Novix Sovereign Studio Pro"
132
  }
133
 
134
  filepath = save_as_flac(sample_rate, audio_data)
135
  return filepath, json.dumps(input_config, indent=2)
136
 
137
 
138
+ # بناء واجهة جرايديو الرسومية المستقرة
139
  with gr.Blocks(title="Novix Sovereign Studio Pro") as demo:
140
  gr.Markdown("# 🎵 استوديو Novix المستقل والمملوك لك بالكامل 100%")
141
+ gr.Markdown("🛡️ تم تطهير سطر التحميل المكسور. المحرك الآن يقرأ ملفات الأوزان محلياً ومستعد للإنتاج.")
142
 
143
  with gr.Row():
144
  with gr.Column():
145
+ lyric = gr.Textbox(label="Lyrics", lines=5, max_lines=15, value=EXAMPLE_LYRICS)
 
 
 
 
 
 
146
 
147
  with gr.Tabs(elem_id="extra-tabs"):
148
  with gr.Tab("Genre Select"):
 
153
  interactive=True
154
  )
155
  with gr.Tab("Text Prompt"):
156
+ description = gr.Textbox(label="Song Description (Optional)", placeholder="female, sad pop, piano", lines=1, max_lines=2)
 
 
 
 
 
 
157
  with gr.Tab("Audio Prompt"):
158
+ prompt_audio = gr.Audio(label="Prompt Audio (Optional)", type="filepath")
 
 
 
159
 
160
  with gr.Accordion("Advanced Config", open=False):
161
  cfg_coef = gr.Slider(label="CFG Coefficient", minimum=0.1, maximum=3.0, step=0.1, value=1.8, interactive=True)
 
174
  outputs=[output_audio, output_json]
175
  )
176
 
 
177
  if __name__ == "__main__":
178
  torch.set_num_threads(1)
179
  ckpt_path = op.join(APP_DIR, "ckpt")
180
 
 
181
  if not op.exists(ckpt_path):
182
  os.makedirs(ckpt_path, exist_ok=True)
183
 
184
+ print("🧠 جاري صهر وبناء بيئة الاستدلال الصوتي المستقل كلياً...")
185
  MODEL = LeVoInference(ckpt_path)
186
+ print("✅ تم تخطي عقبة تحميل الملفات المفقودة والمحرك جاهز كلياً!")
187
 
188
  demo.launch(server_name="0.0.0.0", server_port=7860)