Yeroyan commited on
Commit
14cfa03
·
1 Parent(s): 044429e

add CLI controlled demo

Browse files
README.md CHANGED
@@ -159,7 +159,12 @@ search:
159
 
160
  ```bash
161
  pip install "visual-rag-toolkit[ui,qdrant,embedding,pdf]"
162
- streamlit run demo/app.py
 
 
 
 
 
163
  ```
164
 
165
  ## 📊 Benchmark Evaluation
 
159
 
160
  ```bash
161
  pip install "visual-rag-toolkit[ui,qdrant,embedding,pdf]"
162
+
163
+ # Option A: from Python
164
+ python -c "import visual_rag; visual_rag.demo()"
165
+
166
+ # Option B: CLI launcher
167
+ visual-rag-demo
168
  ```
169
 
170
  ## 📊 Benchmark Evaluation
pyproject.toml CHANGED
@@ -73,6 +73,8 @@ cloudinary = [
73
  ui = [
74
  "streamlit>=1.25.0",
75
  "httpx>=0.24.0",
 
 
76
  ]
77
 
78
  # All dependencies
@@ -90,6 +92,8 @@ all = [
90
  # ui
91
  "streamlit>=1.25.0",
92
  "httpx>=0.24.0",
 
 
93
  ]
94
 
95
  # Development dependencies
@@ -103,6 +107,7 @@ dev = [
103
 
104
  [project.scripts]
105
  visual-rag = "visual_rag.cli.main:main"
 
106
 
107
  [project.urls]
108
  Homepage = "https://github.com/Ara-Yeroyan/visual-rag-toolkit"
@@ -111,7 +116,7 @@ Repository = "https://github.com/Ara-Yeroyan/visual-rag-toolkit"
111
  Issues = "https://github.com/Ara-Yeroyan/visual-rag-toolkit/issues"
112
 
113
  [tool.hatch.build.targets.wheel]
114
- packages = ["visual_rag", "benchmarks"]
115
 
116
  [tool.hatch.build.targets.sdist]
117
  # Keep source distributions clean (no local artifacts, eval results, caches).
 
73
  ui = [
74
  "streamlit>=1.25.0",
75
  "httpx>=0.24.0",
76
+ "pandas>=2.0.0",
77
+ "altair>=5.0.0",
78
  ]
79
 
80
  # All dependencies
 
92
  # ui
93
  "streamlit>=1.25.0",
94
  "httpx>=0.24.0",
95
+ "pandas>=2.0.0",
96
+ "altair>=5.0.0",
97
  ]
98
 
99
  # Development dependencies
 
107
 
108
  [project.scripts]
109
  visual-rag = "visual_rag.cli.main:main"
110
+ visual-rag-demo = "visual_rag.demo_runner:main"
111
 
112
  [project.urls]
113
  Homepage = "https://github.com/Ara-Yeroyan/visual-rag-toolkit"
 
116
  Issues = "https://github.com/Ara-Yeroyan/visual-rag-toolkit/issues"
117
 
118
  [tool.hatch.build.targets.wheel]
119
+ packages = ["visual_rag", "benchmarks", "demo"]
120
 
121
  [tool.hatch.build.targets.sdist]
122
  # Keep source distributions clean (no local artifacts, eval results, caches).
visual_rag/__init__.py CHANGED
@@ -71,6 +71,11 @@ try:
71
  except ImportError:
72
  QdrantAdmin = None
73
 
 
 
 
 
 
74
  # Config utilities (always available)
75
  from visual_rag.config import load_config, get, get_section
76
 
@@ -86,6 +91,7 @@ __all__ = [
86
  "TwoStageRetriever",
87
  "MultiVectorRetriever",
88
  "QdrantAdmin",
 
89
 
90
  # Config utilities
91
  "load_config",
 
71
  except ImportError:
72
  QdrantAdmin = None
73
 
74
+ try:
75
+ from visual_rag.demo_runner import demo
76
+ except ImportError:
77
+ demo = None
78
+
79
  # Config utilities (always available)
80
  from visual_rag.config import load_config, get, get_section
81
 
 
91
  "TwoStageRetriever",
92
  "MultiVectorRetriever",
93
  "QdrantAdmin",
94
+ "demo",
95
 
96
  # Config utilities
97
  "load_config",
visual_rag/demo_runner.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Launch the Streamlit demo from an installed package.
3
+
4
+ Why:
5
+ - After `pip install visual-rag-toolkit`, the repo layout isn't present.
6
+ - We package the `demo/` module and expose `visual_rag.demo()` + `visual-rag-demo`.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import argparse
12
+ import importlib
13
+ import os
14
+ import subprocess
15
+ import sys
16
+ from pathlib import Path
17
+ from typing import Optional
18
+
19
+
20
+ def demo(
21
+ *,
22
+ host: str = "0.0.0.0",
23
+ port: int = 7860,
24
+ headless: bool = True,
25
+ open_browser: bool = False,
26
+ extra_args: Optional[list[str]] = None,
27
+ ) -> int:
28
+ """
29
+ Launch the Streamlit demo UI.
30
+
31
+ Requirements:
32
+ - `visual-rag-toolkit[ui,qdrant,embedding,pdf]` (or `visual-rag-toolkit[all]`)
33
+
34
+ Returns:
35
+ Streamlit process exit code.
36
+ """
37
+ try:
38
+ import streamlit # noqa: F401
39
+ except Exception as e: # pragma: no cover
40
+ raise RuntimeError(
41
+ "Streamlit is not installed. Install with:\n"
42
+ ' pip install "visual-rag-toolkit[ui,qdrant,embedding,pdf]"'
43
+ ) from e
44
+
45
+ # Resolve the installed demo entrypoint path.
46
+ mod = importlib.import_module("demo.app")
47
+ app_path = Path(getattr(mod, "__file__", "")).resolve()
48
+ if not app_path.exists(): # pragma: no cover
49
+ raise RuntimeError("Could not locate installed demo app (demo.app).")
50
+
51
+ # Build a stable Streamlit invocation.
52
+ cmd = [sys.executable, "-m", "streamlit", "run", str(app_path)]
53
+ cmd += ["--server.address", str(host)]
54
+ cmd += ["--server.port", str(int(port))]
55
+ cmd += ["--server.headless", "true" if headless else "false"]
56
+ cmd += ["--browser.gatherUsageStats", "false"]
57
+ cmd += ["--server.runOnSave", "false"]
58
+ cmd += ["--browser.serverAddress", str(host)]
59
+ if not open_browser:
60
+ cmd += ["--browser.serverPort", str(int(port))]
61
+ cmd += ["--browser.open", "false"]
62
+
63
+ if extra_args:
64
+ cmd += list(extra_args)
65
+
66
+ env = os.environ.copy()
67
+ # Make sure the demo doesn't spam internal Streamlit warnings in logs.
68
+ env.setdefault("STREAMLIT_BROWSER_GATHER_USAGE_STATS", "false")
69
+
70
+ return subprocess.call(cmd, env=env)
71
+
72
+
73
+ def main() -> None:
74
+ p = argparse.ArgumentParser(description="Launch the Visual RAG Toolkit Streamlit demo.")
75
+ p.add_argument("--host", default="0.0.0.0")
76
+ p.add_argument("--port", type=int, default=7860)
77
+ p.add_argument("--no-headless", action="store_true", help="Run with a browser window (not headless).")
78
+ p.add_argument("--open", action="store_true", help="Open browser automatically.")
79
+ args, unknown = p.parse_known_args()
80
+
81
+ rc = demo(
82
+ host=args.host,
83
+ port=args.port,
84
+ headless=(not args.no_headless),
85
+ open_browser=bool(args.open),
86
+ extra_args=unknown,
87
+ )
88
+ raise SystemExit(rc)
89
+