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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -33
app.py CHANGED
@@ -1,45 +1,42 @@
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()
 
1
  import os
2
  import zipfile
3
  import subprocess
4
+ import gradio as gr
5
 
6
  ZIP_FILE = "newtons-cradle-simulation.zip"
7
  APP_DIR = "app"
8
 
9
+ # 1. Распаковка
10
  if not os.path.exists(APP_DIR):
11
+ with zipfile.ZipFile(ZIP_FILE, "r") as z:
12
+ z.extractall(APP_DIR)
13
+
14
+ # 2. npm install
15
+ subprocess.run(["npm", "install"], cwd=APP_DIR, check=False)
16
+
17
+ # 3. npm build
18
+ subprocess.run(["npm", "run", "build"], cwd=APP_DIR, check=False)
19
+
20
+ # 4. Определяем index.html
21
+ INDEX_HTML = None
22
+ for p in ["dist/index.html", "build/index.html", "public/index.html"]:
23
+ full = os.path.join(APP_DIR, p)
24
+ if os.path.exists(full):
25
+ INDEX_HTML = full
26
+ break
27
+
28
+ if INDEX_HTML is None:
29
+ raise RuntimeError("index.html not found after build")
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ # 5. Gradio UI
32
  with gr.Blocks() as demo:
33
+ gr.HTML(f"""
34
+ <iframe
35
+ src="file={INDEX_HTML}"
36
+ width="100%"
37
+ height="700"
38
+ style="border:none;"
39
+ ></iframe>
40
+ """)
41
 
42
  demo.launch()