nikolaife commited on
Commit
77e4367
·
verified ·
1 Parent(s): b6c2ca1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -15
app.py CHANGED
@@ -1,32 +1,45 @@
1
  import os
2
  import zipfile
3
  import subprocess
 
4
 
5
  ZIP_FILE = "newtons-cradle-simulation.zip"
6
  APP_DIR = "app"
7
 
8
- # 1. Распаковка архива
9
  if not os.path.exists(APP_DIR):
10
  if os.path.exists(ZIP_FILE):
11
  with zipfile.ZipFile(ZIP_FILE, "r") as z:
12
  z.extractall(APP_DIR)
 
13
  else:
14
- raise FileNotFoundError(f"{ZIP_FILE} not found")
15
 
16
- # 2. npm install (если npm есть)
17
- try:
18
- subprocess.run(
19
- ["npm", "install"],
20
- cwd=APP_DIR,
21
- check=False,
22
- stdout=subprocess.PIPE,
23
- stderr=subprocess.PIPE,
24
- )
25
- except Exception as e:
26
- print("npm install skipped:", e)
 
 
 
 
 
 
 
 
 
27
 
28
- # 3. Минимальный Gradio (чтобы Space не падал)
29
  import gradio as gr
30
 
31
- demo = gr.Markdown("✅ Archive extracted. Check logs.")
 
 
32
  demo.launch()
 
1
  import os
2
  import zipfile
3
  import subprocess
4
+ import sys
5
 
6
  ZIP_FILE = "newtons-cradle-simulation.zip"
7
  APP_DIR = "app"
8
 
9
+ # 1) Распаковка
10
  if not os.path.exists(APP_DIR):
11
  if os.path.exists(ZIP_FILE):
12
  with zipfile.ZipFile(ZIP_FILE, "r") as z:
13
  z.extractall(APP_DIR)
14
+ print(f"Archive extracted to '{APP_DIR}'")
15
  else:
16
+ print(f"WARNING: {ZIP_FILE} not found in repo root")
17
 
18
+ # 2) npm install (попытка — ошибки не прервут работу)
19
+ if os.path.exists(APP_DIR):
20
+ try:
21
+ res = subprocess.run(
22
+ ["npm", "install"],
23
+ cwd=APP_DIR,
24
+ capture_output=True,
25
+ text=True,
26
+ )
27
+ print("npm install returncode:", res.returncode)
28
+ if res.stdout:
29
+ print("--- npm stdout ---")
30
+ print(res.stdout)
31
+ if res.stderr:
32
+ print("--- npm stderr ---", file=sys.stderr)
33
+ print(res.stderr, file=sys.stderr)
34
+ except Exception as e:
35
+ print("npm install skipped:", e)
36
+ else:
37
+ print("Skipping npm install because app directory is missing")
38
 
39
+ # 3) Gradio UI — Blocks, чтобы можно было вызвать .launch()
40
  import gradio as gr
41
 
42
+ with gr.Blocks() as demo:
43
+ gr.Markdown("✅ Attempted: archive extraction and `npm install`.\n\nПосмотри вкладку **Files** и **Logs** для деталей.")
44
+
45
  demo.launch()