Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,42 @@
|
|
| 1 |
import os
|
| 2 |
import zipfile
|
| 3 |
import subprocess
|
| 4 |
-
import
|
| 5 |
|
| 6 |
ZIP_FILE = "newtons-cradle-simulation.zip"
|
| 7 |
APP_DIR = "app"
|
| 8 |
|
| 9 |
-
# 1
|
| 10 |
if not os.path.exists(APP_DIR):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|