AlaBoussoffara commited on
Commit
4c58b1a
·
1 Parent(s): 13458f8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py — wrapper used by Hugging Face Spaces to start the Chainlit UI
2
+ # This simple script locates the packaged chainlit app and invokes the chainlit CLI.
3
+
4
+ import os
5
+ import subprocess
6
+ from pathlib import Path
7
+ import sys
8
+
9
+ # Optional: set a default model name here or use Space env vars to override
10
+ # os.environ.setdefault("MINI_TRANSFORMER_MODEL_NAME", "small_model_v1")
11
+
12
+ # Resolve path to packaged chainlit app inside the repository
13
+ app_path = Path(__file__).parent / "src" / "mini_transformer" / "apps" / "chainlit_app.py"
14
+ if not app_path.exists():
15
+ # If package is installed into env, try to find installed module
16
+ try:
17
+ import mini_transformer.apps.chainlit_app as packed
18
+
19
+ app_path = Path(packed.__file__)
20
+ except Exception:
21
+ print("Could not locate mini_transformer.apps.chainlit_app. Make sure package files are present.", file=sys.stderr)
22
+ raise SystemExit(1)
23
+
24
+ port = os.environ.get("PORT", os.environ.get("MINI_TRANSFORMER_UI_PORT", "7860"))
25
+ host = os.environ.get("HOST", "0.0.0.0")
26
+
27
+ cmd = ["chainlit", "run", str(app_path), "--host", host, "--port", str(port)]
28
+ print("Starting Chainlit with:\n", " ".join(cmd))
29
+
30
+ # Use subprocess.run so Chainlit becomes the foreground process
31
+ try:
32
+ subprocess.run(cmd, check=True)
33
+ except FileNotFoundError:
34
+ print("'chainlit' CLI not found. Ensure 'chainlit' is in requirements.txt and installed.", file=sys.stderr)
35
+ raise