Kremon96 commited on
Commit
3954a74
·
verified ·
1 Parent(s): 1c31533

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -23
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py (с авто-инициализацией)
2
  import gradio as gr
3
  import os
4
  import time
@@ -19,12 +19,32 @@ def create_zip_archive(output_dir):
19
  zipf.write(file_path, file_path.relative_to(output_dir))
20
  return str(zip_path)
21
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  def separate_audio_interface(audio_file, progress=gr.Progress()):
23
  """Gradio interface function for audio separation"""
24
  if not audio_file:
25
  return "❌ Пожалуйста, загрузите аудиофайл", None
26
 
27
  try:
 
 
 
 
 
 
 
 
28
  # Save uploaded file
29
  audio_path = AUDIO_DIR / f"input_{int(time.time())}{Path(audio_file).suffix}"
30
  with open(audio_path, "wb") as f:
@@ -51,19 +71,6 @@ def separate_audio_interface(audio_file, progress=gr.Progress()):
51
  except Exception as e:
52
  return f"❌ Ошибка обработки: {str(e)}", None
53
 
54
- def get_system_status():
55
- """Get current system status"""
56
- system_info = separator_app.get_system_info()
57
-
58
- if system_info['initialized']:
59
- return "✅ Система готова к работе!", "success"
60
- elif separator_app.initializing:
61
- return "🔄 Система инициализируется...", "warning"
62
- elif separator_app.init_error:
63
- return f"❌ Ошибка инициализации: {separator_app.init_error}", "error"
64
- else:
65
- return "⚪ Статус неизвестен", "neutral"
66
-
67
  def get_example_files():
68
  """Get example files for demo"""
69
  examples_dir = Path("examples")
@@ -99,7 +106,7 @@ with gr.Blocks(
99
  # System status display
100
  with gr.Row():
101
  status_display = gr.HTML(
102
- value="<div class='status-warning'>🔄 Система инициализируется...</div>",
103
  label="Статус системы"
104
  )
105
 
@@ -177,14 +184,6 @@ with gr.Blocks(
177
  - Архив содержит 5 отдельных дорожек для профессиональной работы
178
  """)
179
 
180
- # JavaScript для обновления статуса
181
- demo.load(
182
- fn=get_system_status,
183
- inputs=[],
184
- outputs=[status_display],
185
- every=2 # Обновлять каждые 2 секунды
186
- )
187
-
188
  # Event handlers
189
  process_btn.click(
190
  fn=separate_audio_interface,
@@ -197,6 +196,11 @@ if __name__ == "__main__":
197
  print("🚀 Запуск Music Source Separator...")
198
  print("🔄 Начата автоматическая инициализация моделей...")
199
 
 
 
 
 
 
200
  demo.launch(
201
  server_name="0.0.0.0",
202
  server_port=7860,
 
1
+ # app.py (исправленная версия)
2
  import gradio as gr
3
  import os
4
  import time
 
19
  zipf.write(file_path, file_path.relative_to(output_dir))
20
  return str(zip_path)
21
 
22
+ def get_initial_status():
23
+ """Get initial system status"""
24
+ system_info = separator_app.get_system_info()
25
+ if system_info['initialized']:
26
+ return "✅ Система готова к работе!"
27
+ elif separator_app.initializing:
28
+ return "🔄 Система инициализируется..."
29
+ elif separator_app.init_error:
30
+ return f"❌ Ошибка инициализации: {separator_app.init_error}"
31
+ else:
32
+ return "⚪ Статус неизвестен"
33
+
34
  def separate_audio_interface(audio_file, progress=gr.Progress()):
35
  """Gradio interface function for audio separation"""
36
  if not audio_file:
37
  return "❌ Пожалуйста, загрузите аудиофайл", None
38
 
39
  try:
40
+ # Check if system is ready
41
+ if not separator_app.initialized and separator_app.initializing:
42
+ return "🔄 Система все еще инициализируется. Пожалуйста, подождите...", None
43
+ elif not separator_app.initialized and separator_app.init_error:
44
+ return f"❌ Система не готова: {separator_app.init_error}", None
45
+ elif not separator_app.initialized:
46
+ return "❌ Система не инициализирована", None
47
+
48
  # Save uploaded file
49
  audio_path = AUDIO_DIR / f"input_{int(time.time())}{Path(audio_file).suffix}"
50
  with open(audio_path, "wb") as f:
 
71
  except Exception as e:
72
  return f"❌ Ошибка обработки: {str(e)}", None
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  def get_example_files():
75
  """Get example files for demo"""
76
  examples_dir = Path("examples")
 
106
  # System status display
107
  with gr.Row():
108
  status_display = gr.HTML(
109
+ value=f"<div class='status-warning'>{get_initial_status()}</div>",
110
  label="Статус системы"
111
  )
112
 
 
184
  - Архив содержит 5 отдельных дорожек для профессиональной работы
185
  """)
186
 
 
 
 
 
 
 
 
 
187
  # Event handlers
188
  process_btn.click(
189
  fn=separate_audio_interface,
 
196
  print("🚀 Запуск Music Source Separator...")
197
  print("🔄 Начата автоматическая инициализация моделей...")
198
 
199
+ # Check system status after a short delay to show initialization progress
200
+ time.sleep(2)
201
+ initial_status = get_initial_status()
202
+ print(f"Статус системы: {initial_status}")
203
+
204
  demo.launch(
205
  server_name="0.0.0.0",
206
  server_port=7860,