Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 15 |
|
| 16 |
-
# 2
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
# 3
|
| 29 |
import gradio as gr
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
| 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()
|