search-api-webui 0.1.6__tar.gz → 0.1.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. {search_api_webui-0.1.6 → search_api_webui-0.1.8}/.gitignore +1 -1
  2. search_api_webui-0.1.8/PKG-INFO +146 -0
  3. search_api_webui-0.1.6/PKG-INFO → search_api_webui-0.1.8/README.md +21 -27
  4. {search_api_webui-0.1.6 → search_api_webui-0.1.8}/pyproject.toml +13 -9
  5. {search_api_webui-0.1.6 → search_api_webui-0.1.8}/search_api_webui/__init__.py +0 -1
  6. search_api_webui-0.1.8/search_api_webui/app.py +289 -0
  7. {search_api_webui-0.1.6 → search_api_webui-0.1.8}/search_api_webui/providers/__init__.py +10 -7
  8. search_api_webui-0.1.8/search_api_webui/providers/base.py +105 -0
  9. {search_api_webui-0.1.6 → search_api_webui-0.1.8}/search_api_webui/providers/generic.py +70 -43
  10. {search_api_webui-0.1.6 → search_api_webui-0.1.8}/search_api_webui/providers/querit.py +42 -33
  11. search_api_webui-0.1.8/search_api_webui/providers.yaml +77 -0
  12. search_api_webui-0.1.8/search_api_webui/ruff.toml +27 -0
  13. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/altgraph-0.17.5.dist-info/LICENSE +18 -0
  14. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/bottle-0.13.4.dist-info/licenses/LICENSE +19 -0
  15. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/certifi-2026.1.4.dist-info/licenses/LICENSE +20 -0
  16. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/charset_normalizer-3.4.4.dist-info/licenses/LICENSE +21 -0
  17. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/flask/sansio/README.md +6 -0
  18. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/jmespath-1.1.0.dist-info/LICENSE +21 -0
  19. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/macholib-1.16.4.dist-info/LICENSE +21 -0
  20. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/packaging-26.0.dist-info/licenses/LICENSE +3 -0
  21. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/certifi/LICENSE +20 -0
  22. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/distro/LICENSE +202 -0
  23. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/packaging/LICENSE +3 -0
  24. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/pkg_resources/LICENSE +17 -0
  25. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/platformdirs/LICENSE +21 -0
  26. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/pygments/LICENSE +25 -0
  27. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/LICENSE +21 -0
  28. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/requests/LICENSE +175 -0
  29. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/resolvelib/LICENSE +13 -0
  30. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/rich/LICENSE +19 -0
  31. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/tomli/LICENSE +21 -0
  32. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/tomli_w/LICENSE +21 -0
  33. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip/_vendor/truststore/LICENSE +21 -0
  34. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/certifi/LICENSE +20 -0
  35. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/distro/LICENSE +202 -0
  36. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/packaging/LICENSE +3 -0
  37. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/pkg_resources/LICENSE +17 -0
  38. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/platformdirs/LICENSE +21 -0
  39. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/pygments/LICENSE +25 -0
  40. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/pyproject_hooks/LICENSE +21 -0
  41. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/requests/LICENSE +175 -0
  42. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/resolvelib/LICENSE +13 -0
  43. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/rich/LICENSE +19 -0
  44. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/tomli/LICENSE +21 -0
  45. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/tomli_w/LICENSE +21 -0
  46. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pip-25.3.dist-info/licenses/src/pip/_vendor/truststore/LICENSE +21 -0
  47. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pyinstaller_hooks_contrib-2026.0.dist-info/licenses/LICENSE +521 -0
  48. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pywebview-6.1.dist-info/licenses/LICENSE +29 -0
  49. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/pyyaml-6.0.3.dist-info/licenses/LICENSE +20 -0
  50. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/querit-0.1.2.dist-info/licenses/LICENSE +201 -0
  51. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/requests-2.32.5.dist-info/licenses/LICENSE +175 -0
  52. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/search_api_webui/static/AppIcon.icns +0 -0
  53. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/search_api_webui/static/assets/index-B3BapgR8.css +1 -0
  54. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/search_api_webui/static/assets/index-DqsQFaWm.js +196 -0
  55. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/search_api_webui/static/favicon.ico +0 -0
  56. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/search_api_webui/static/index.html +14 -0
  57. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/search_api_webui-0.1.7.dist-info/licenses/LICENSE +7 -0
  58. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/setuptools-65.5.0.dist-info/LICENSE +19 -0
  59. search_api_webui-0.1.8/venv-macos-build/lib/python3.11/site-packages/typing_extensions-4.15.0.dist-info/licenses/LICENSE +279 -0
  60. search_api_webui-0.1.6/README.md +0 -100
  61. search_api_webui-0.1.6/search_api_webui/app.py +0 -194
  62. search_api_webui-0.1.6/search_api_webui/providers/base.py +0 -45
  63. search_api_webui-0.1.6/search_api_webui/providers.yaml +0 -19
  64. {search_api_webui-0.1.6 → search_api_webui-0.1.8}/LICENSE +0 -0
@@ -8,7 +8,6 @@ venv/
8
8
  # Frontend / Node
9
9
  frontend/node_modules/
10
10
  frontend/dist/
11
- frontend/package-lock.json
12
11
  frontend/.DS_Store
13
12
  .DS_Store
14
13
 
@@ -24,6 +23,7 @@ user_config.json
24
23
  .co*/
25
24
  .tr*/
26
25
  .hi*/
26
+ .ba*/
27
27
 
28
28
  # Build artifacts
29
29
  build/
@@ -0,0 +1,146 @@
1
+ Metadata-Version: 2.4
2
+ Name: search-api-webui
3
+ Version: 0.1.8
4
+ Summary: A Search API WebUI for testing and comparing Querit, You, and other search providers.
5
+ Project-URL: Homepage, https://github.com/querit-ai/search-api-webui
6
+ Project-URL: Repository, https://github.com/querit-ai/search-api-webui.git
7
+ Project-URL: Issues, https://github.com/querit-ai/search-api-webui/issues
8
+ Author: querit.ai
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: api,arena,benchmark,llm,querit,search,tool,webui
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: Flask
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Requires-Python: >=3.8
17
+ Requires-Dist: flask-cors>=3.0.0
18
+ Requires-Dist: flask>=1.1.0
19
+ Requires-Dist: jmespath>=0.10.0
20
+ Requires-Dist: pyyaml>=5.3
21
+ Requires-Dist: querit
22
+ Requires-Dist: requests>=2.22.0
23
+ Provides-Extra: build
24
+ Requires-Dist: pyinstaller>=6.0; extra == 'build'
25
+ Provides-Extra: webview
26
+ Requires-Dist: pywebview>=5.0; extra == 'webview'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Search API WebUI
30
+
31
+ A lightweight, local WebUI for testing, comparing, and visualizing Search APIs (Querit, You, etc.).
32
+
33
+ ![Screenshot](docs/images/screenshot.webp)
34
+
35
+ ## Features
36
+
37
+ * **Search**: Support for [Querit.ai](https://www.querit.ai/en/docs/reference/post), [You.com](https://docs.you.com/api-reference/search/v1-search), and generic Search APIs via configuration.
38
+ * **API Arena**: Compare two search providers side-by-side to benchmark latency, payload size, and result relevance.
39
+ * **Performance Metrics**: Real-time display of request latency and payload size.
40
+ * **Visual Rendering**: Renders standard search results (Title, Snippet, URL) in a clean card layout.
41
+ * **Configurable**: Easy-to-edit providers.yaml to add or modify search providers.
42
+ * **Secure**: API Keys are stored locally in your $HOME folder.
43
+ ## Installation
44
+
45
+ ### macOS Installation
46
+
47
+ For macOS users, you can download the DMG installer from the GitHub Releases page:
48
+
49
+ 1. Visit the [Releases page](https://github.com/querit-ai/search-api-webui/releases)
50
+ 2. Download the appropriate DMG file for your Mac architecture:
51
+ - **Apple Silicon (M1/M2/M3)**: `SearchAPIWebUI-<version>-macOS-arm64.dmg`
52
+ - **Intel Macs**: `SearchAPIWebUI-<version>-macOS-x86_64.dmg`
53
+ 3. Open the DMG file and drag `SearchAPIWebUI` to your Applications folder
54
+ 4. Launch `SearchAPIWebUI` from Applications
55
+
56
+ **Note**: Since the application is not code-signed, macOS may block it on first launch. To allow it to run:
57
+ - Go to **System Settings** > **Privacy & Security**
58
+ - Look for the message about `SearchAPIWebUI` being blocked
59
+ - Click **Open Anyway** to allow the application to run
60
+
61
+ ### Prerequisites
62
+
63
+ Python 3.7+
64
+
65
+ ### Install via Pip
66
+
67
+ Use this method if you just want to run the tool without modifying the code.
68
+
69
+ ```
70
+ pip install search-api-webui
71
+ ```
72
+
73
+ ### Run the Server
74
+
75
+ ```
76
+ search-api-webui
77
+ ```
78
+
79
+ ## Development
80
+
81
+ Use this method if you want to contribute to the code or build from source.
82
+
83
+ ### Prerequisites
84
+
85
+ * Python 3.7+
86
+ * Node.js & npm (for building the frontend)
87
+
88
+ ### Setup Steps
89
+
90
+ **Clone the repository**
91
+
92
+ ```
93
+ git clone https://github.com/querit-ai/search-api-webui.git
94
+ cd search-api-webui
95
+ ```
96
+
97
+ **Build Frontend**
98
+
99
+ ```
100
+ cd frontend
101
+ npm install
102
+ npm run build
103
+ cd …
104
+ ```
105
+
106
+ **Install search-api-webui (Editable Mode)**
107
+
108
+ ```
109
+ pip install -e .
110
+ ```
111
+
112
+ **Run the Server**
113
+
114
+ ```
115
+ python -m search_api_webui.app
116
+ ```
117
+
118
+ ## Configuration
119
+
120
+ ### Add API Keys
121
+
122
+ Open the WebUI settings page (click the gear icon). Enter your API Key for the selected provider (e.g., Querit). Keys are saved locally in $HOME/.search-api-webui/config.json.
123
+
124
+ ### Add New Providers
125
+
126
+ Edit providers.yaml in the root directory to add custom API endpoints. The system uses JMESPath to map JSON responses to the UI.
127
+
128
+ ```
129
+ my_custom_search:
130
+ url: “https://api.example.com/search”
131
+ method: “GET”
132
+ headers:
133
+ Authorization: “Bearer {api_key}”
134
+ params:
135
+ q: “{query}”
136
+ response_mapping:
137
+ root_path: “data.items”
138
+ fields:
139
+ title: “title”
140
+ url: “link”
141
+ snippet: “snippet”
142
+ ```
143
+
144
+ ## License
145
+
146
+ MIT License. See LICENSE for details.
@@ -1,49 +1,43 @@
1
- Metadata-Version: 2.4
2
- Name: search-api-webui
3
- Version: 0.1.6
4
- Summary: A Search API WebUI for Querit, You, and other search providers.
5
- Project-URL: Homepage, https://github.com/querit-ai/search-api-webui
6
- Project-URL: Repository, https://github.com/querit-ai/search-api-webui.git
7
- Project-URL: Issues, https://github.com/querit-ai/search-api-webui/issues
8
- Author: querit.ai
9
- License: MIT
10
- License-File: LICENSE
11
- Keywords: api,llm,querit,search,tool,webui
12
- Classifier: Development Status :: 3 - Alpha
13
- Classifier: Framework :: Flask
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Programming Language :: Python :: 3
16
- Requires-Python: >=3.7
17
- Requires-Dist: flask-cors
18
- Requires-Dist: flask>=2.0.0
19
- Requires-Dist: jmespath
20
- Requires-Dist: pyyaml>=6.0
21
- Requires-Dist: querit
22
- Requires-Dist: requests>=2.25.0
23
- Description-Content-Type: text/markdown
24
-
25
1
  # Search API WebUI
26
2
 
27
- A lightweight, local WebUI for testing and visualizing Search APIs (Querit, You, etc.).
3
+ A lightweight, local WebUI for testing, comparing, and visualizing Search APIs (Querit, You, etc.).
28
4
 
29
- (images)
5
+ ![Screenshot](docs/images/screenshot.webp)
30
6
 
31
7
  ## Features
32
8
 
33
9
  * **Search**: Support for [Querit.ai](https://www.querit.ai/en/docs/reference/post), [You.com](https://docs.you.com/api-reference/search/v1-search), and generic Search APIs via configuration.
10
+ * **API Arena**: Compare two search providers side-by-side to benchmark latency, payload size, and result relevance.
34
11
  * **Performance Metrics**: Real-time display of request latency and payload size.
35
12
  * **Visual Rendering**: Renders standard search results (Title, Snippet, URL) in a clean card layout.
36
13
  * **Configurable**: Easy-to-edit providers.yaml to add or modify search providers.
37
14
  * **Secure**: API Keys are stored locally in your $HOME folder.
38
15
  ## Installation
39
16
 
40
- Use this method if you just want to run the tool without modifying the code.
17
+ ### macOS Installation
18
+
19
+ For macOS users, you can download the DMG installer from the GitHub Releases page:
20
+
21
+ 1. Visit the [Releases page](https://github.com/querit-ai/search-api-webui/releases)
22
+ 2. Download the appropriate DMG file for your Mac architecture:
23
+ - **Apple Silicon (M1/M2/M3)**: `SearchAPIWebUI-<version>-macOS-arm64.dmg`
24
+ - **Intel Macs**: `SearchAPIWebUI-<version>-macOS-x86_64.dmg`
25
+ 3. Open the DMG file and drag `SearchAPIWebUI` to your Applications folder
26
+ 4. Launch `SearchAPIWebUI` from Applications
27
+
28
+ **Note**: Since the application is not code-signed, macOS may block it on first launch. To allow it to run:
29
+ - Go to **System Settings** > **Privacy & Security**
30
+ - Look for the message about `SearchAPIWebUI` being blocked
31
+ - Click **Open Anyway** to allow the application to run
41
32
 
42
33
  ### Prerequisites
43
34
 
44
35
  Python 3.7+
36
+
45
37
  ### Install via Pip
46
38
 
39
+ Use this method if you just want to run the tool without modifying the code.
40
+
47
41
  ```
48
42
  pip install search-api-webui
49
43
  ```
@@ -4,15 +4,15 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "search-api-webui"
7
- version = "0.1.6"
8
- description = "A Search API WebUI for Querit, You, and other search providers."
7
+ version = "0.1.8"
8
+ description = "A Search API WebUI for testing and comparing Querit, You, and other search providers."
9
9
  readme = "README.md"
10
- requires-python = ">=3.7"
10
+ requires-python = ">=3.8"
11
11
  license = { text = "MIT" }
12
12
  authors = [
13
13
  { name = "querit.ai" }
14
14
  ]
15
- keywords = ["search", "api", "webui", "querit", "llm", "tool"]
15
+ keywords = ["search", "api", "webui", "querit", "llm", "tool", "arena", "benchmark"]
16
16
  classifiers = [
17
17
  "Development Status :: 3 - Alpha",
18
18
  "License :: OSI Approved :: MIT License",
@@ -21,14 +21,18 @@ classifiers = [
21
21
  ]
22
22
 
23
23
  dependencies = [
24
- "flask>=2.0.0",
25
- "flask-cors",
26
- "requests>=2.25.0",
27
- "pyyaml>=6.0",
28
- "jmespath",
24
+ "flask>=1.1.0",
25
+ "flask-cors>=3.0.0",
26
+ "requests>=2.22.0",
27
+ "pyyaml>=5.3",
28
+ "jmespath>=0.10.0",
29
29
  "querit"
30
30
  ]
31
31
 
32
+ [project.optional-dependencies]
33
+ webview = ["pywebview>=5.0"]
34
+ build = ["pyinstaller>=6.0"]
35
+
32
36
  [project.urls]
33
37
  Homepage = "https://github.com/querit-ai/search-api-webui"
34
38
  Repository = "https://github.com/querit-ai/search-api-webui.git"
@@ -17,4 +17,3 @@
17
17
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
18
  # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19
19
  # DEALINGS IN THE SOFTWARE.
20
-
@@ -0,0 +1,289 @@
1
+ # Copyright (c) 2026 QUERIT PRIVATE LIMITED
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to
5
+ # deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ # sell copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19
+ # DEALINGS IN THE SOFTWARE.
20
+
21
+ import json
22
+ import socket
23
+ import sys
24
+ import threading
25
+ import time
26
+ import webbrowser
27
+ from pathlib import Path
28
+
29
+ from flask import Flask, jsonify, request, send_from_directory
30
+ from flask_cors import CORS
31
+
32
+ from search_api_webui.providers import load_providers
33
+
34
+ try:
35
+ import webview
36
+ WEBVIEW_AVAILABLE = True
37
+ except ImportError:
38
+ WEBVIEW_AVAILABLE = False
39
+
40
+
41
+ def get_resource_path(relative_path):
42
+ '''Get absolute path to resource, works for dev and for PyInstaller.'''
43
+ try:
44
+ # PyInstaller creates a temp folder and stores path in _MEIPASS
45
+ base_path = Path(sys._MEIPASS)
46
+ except Exception:
47
+ base_path = Path(__file__).resolve().parent
48
+
49
+ return base_path / relative_path
50
+
51
+
52
+ CURRENT_DIR = Path(__file__).resolve().parent
53
+
54
+ # Handle static folder for both dev and packaged app
55
+ if hasattr(sys, '_MEIPASS'):
56
+ # Running in PyInstaller bundle
57
+ STATIC_FOLDER = Path(sys._MEIPASS) / 'static'
58
+ else:
59
+ # Running in development
60
+ STATIC_FOLDER = CURRENT_DIR / 'static'
61
+ if not STATIC_FOLDER.exists():
62
+ DEV_FRONTEND_DIST = CURRENT_DIR.parent / 'frontend' / 'dist'
63
+ if DEV_FRONTEND_DIST.exists():
64
+ STATIC_FOLDER = DEV_FRONTEND_DIST
65
+
66
+ app = Flask(__name__, static_folder=str(STATIC_FOLDER))
67
+ CORS(app)
68
+
69
+ # Use get_resource_path for providers.yaml
70
+ PROVIDERS_YAML = get_resource_path('providers.yaml')
71
+ USER_CONFIG_DIR = Path.home() / '.search-api-webui'
72
+ USER_CONFIG_JSON = USER_CONFIG_DIR / 'config.json'
73
+
74
+ if not USER_CONFIG_DIR.exists():
75
+ USER_CONFIG_DIR.mkdir(parents=True, exist_ok=True)
76
+
77
+ if PROVIDERS_YAML.exists():
78
+ provider_map = load_providers(str(PROVIDERS_YAML))
79
+ else:
80
+ print(f'Error: Configuration file not found at {PROVIDERS_YAML}')
81
+ provider_map = {}
82
+
83
+
84
+ def get_stored_config():
85
+ if not USER_CONFIG_JSON.exists():
86
+ return {}
87
+ try:
88
+ with open(USER_CONFIG_JSON, encoding='utf-8') as f:
89
+ return json.load(f)
90
+ except Exception as e:
91
+ print(f'Error reading config: {e}')
92
+ return {}
93
+
94
+
95
+ def save_stored_config(config_dict):
96
+ try:
97
+ with open(USER_CONFIG_JSON, 'w', encoding='utf-8') as f:
98
+ json.dump(config_dict, f, indent=2)
99
+ except Exception as e:
100
+ print(f'Error saving config: {e}')
101
+
102
+
103
+ @app.route('/api/providers', methods=['GET'])
104
+ def get_providers_list():
105
+ stored_config = get_stored_config()
106
+ providers_info = []
107
+
108
+ for name, provider_instance in provider_map.items():
109
+ config_details = provider_instance.config
110
+
111
+ user_conf = stored_config.get(name, {})
112
+
113
+ if isinstance(user_conf, str):
114
+ user_conf = {'api_key': user_conf}
115
+
116
+ has_key = bool(user_conf.get('api_key'))
117
+
118
+ providers_info.append(
119
+ {
120
+ 'name': name,
121
+ 'has_key': has_key,
122
+ 'details': config_details,
123
+ 'user_settings': {
124
+ 'api_url': user_conf.get('api_url', ''),
125
+ 'limit': user_conf.get('limit', '10'),
126
+ 'language': user_conf.get('language', 'en-US'),
127
+ },
128
+ },
129
+ )
130
+ return jsonify(providers_info)
131
+
132
+
133
+ @app.route('/api/config', methods=['POST'])
134
+ def update_config():
135
+ data = request.json
136
+ provider_name = data.get('provider')
137
+
138
+ if not provider_name:
139
+ return jsonify({'error': 'Provider name is required'}), 400
140
+
141
+ if 'api_key' not in data:
142
+ return jsonify({'error': 'API Key field is missing'}), 400
143
+
144
+ api_key = data.get('api_key')
145
+
146
+ api_url = data.get('api_url', '').strip()
147
+ limit = data.get('limit', '10')
148
+ language = data.get('language', 'en-US')
149
+
150
+ all_config = get_stored_config()
151
+
152
+ if provider_name in all_config and isinstance(all_config[provider_name], str):
153
+ all_config[provider_name] = {'api_key': all_config[provider_name]}
154
+
155
+ if not api_key:
156
+ if provider_name in all_config:
157
+ all_config[provider_name]['api_key'] = ''
158
+ else:
159
+ if provider_name not in all_config:
160
+ all_config[provider_name] = {}
161
+
162
+ all_config[provider_name]['api_key'] = api_key
163
+ all_config[provider_name]['api_url'] = api_url
164
+ all_config[provider_name]['limit'] = limit
165
+ all_config[provider_name]['language'] = language
166
+
167
+ save_stored_config(all_config)
168
+ return jsonify({'status': 'success'})
169
+
170
+
171
+ @app.route('/api/search', methods=['POST'])
172
+ def search_api():
173
+ data = request.json
174
+ query = data.get('query')
175
+ provider_name = data.get('provider', 'querit')
176
+
177
+ api_key = data.get('api_key')
178
+
179
+ stored_config = get_stored_config()
180
+ provider_config = stored_config.get(provider_name, {})
181
+
182
+ if isinstance(provider_config, str):
183
+ provider_config = {'api_key': provider_config}
184
+
185
+ if not api_key:
186
+ api_key = provider_config.get('api_key')
187
+
188
+ if not api_key:
189
+ return (
190
+ jsonify({'error': f'API Key for {provider_name} is missing. Please configure it.'}),
191
+ 401,
192
+ )
193
+
194
+ provider = provider_map.get(provider_name)
195
+ if not provider:
196
+ return jsonify({'error': 'Provider not found'}), 404
197
+
198
+ search_kwargs = {
199
+ 'api_url': provider_config.get('api_url'),
200
+ 'limit': provider_config.get('limit'),
201
+ 'language': provider_config.get('language'),
202
+ }
203
+
204
+ result = provider.search(query, api_key, **search_kwargs)
205
+ return jsonify(result)
206
+
207
+
208
+ # Host React Frontend
209
+ @app.route('/', defaults={'path': ''})
210
+ @app.route('/<path:path>')
211
+ def serve(path):
212
+ if path != '' and (STATIC_FOLDER / path).exists():
213
+ return send_from_directory(str(STATIC_FOLDER), path)
214
+ else:
215
+ return send_from_directory(str(STATIC_FOLDER), 'index.html')
216
+
217
+
218
+ def wait_for_server_ready(host, port):
219
+ start_time = time.time()
220
+ while time.time() - start_time < 10:
221
+ try:
222
+ with socket.create_connection((host, port), timeout=1):
223
+ return True
224
+ except (OSError, ConnectionRefusedError):
225
+ time.sleep(0.1)
226
+ return False
227
+
228
+
229
+ def main():
230
+ import argparse
231
+
232
+ parser = argparse.ArgumentParser(description='Search API WebUI')
233
+ parser.add_argument('--port', type=int, default=8889, help='Port to run the server on')
234
+ parser.add_argument('--host', type=str, default='127.0.0.1', help='Host to run the server on')
235
+ parser.add_argument('-w', '--webview', action='store_true', help='Use webview to open the application')
236
+ args = parser.parse_args()
237
+
238
+ url = f'http://{args.host}:{args.port}'
239
+ print('Starting Search API WebUI...')
240
+ print(f' - Config Storage: {USER_CONFIG_JSON}')
241
+ print(f' - Serving on: {url}')
242
+ if args.webview:
243
+ print(' - Mode: webview')
244
+
245
+ if args.webview:
246
+ if not WEBVIEW_AVAILABLE:
247
+ print('Warning: webview library not installed. Falling back to webbrowser.')
248
+ # Start server in background thread and wait for it to be ready
249
+ server_thread = threading.Thread(
250
+ target=lambda: app.run(
251
+ host=args.host, port=args.port, use_reloader=False,
252
+ ),
253
+ daemon=True,
254
+ )
255
+ server_thread.start()
256
+ if wait_for_server_ready(args.host, args.port):
257
+ print(f'Server is ready! Opening browser: {url}')
258
+ webbrowser.open(url)
259
+ else:
260
+ print('Error: Server took too long to start. Browser not opened.')
261
+ else:
262
+ # Start server in background thread and wait for it to be ready, then start webview
263
+ server_thread = threading.Thread(
264
+ target=lambda: app.run(
265
+ host=args.host, port=args.port, use_reloader=False,
266
+ ),
267
+ daemon=True,
268
+ )
269
+ server_thread.start()
270
+ if wait_for_server_ready(args.host, args.port):
271
+ print('Server is ready! Using webview mode...')
272
+ webview.create_window('Search API WebUI', url, width=1200, height=800)
273
+ webview.start()
274
+ else:
275
+ print('Error: Server took too long to start. Webview not opened.')
276
+ else:
277
+ # Start a background thread to check server status and open the browser automatically
278
+ def open_browser():
279
+ if wait_for_server_ready(args.host, args.port):
280
+ print(f'Server is ready! Opening browser: {url}')
281
+ webbrowser.open(url)
282
+ else:
283
+ print('Error: Server took too long to start. Browser not opened.')
284
+ threading.Thread(target=open_browser, daemon=True).start()
285
+ app.run(host=args.host, port=args.port)
286
+
287
+
288
+ if __name__ == '__main__':
289
+ main()
@@ -19,25 +19,28 @@
19
19
  # DEALINGS IN THE SOFTWARE.
20
20
 
21
21
  import os
22
+
22
23
  import yaml
24
+
23
25
  from .generic import GenericProvider
24
26
  from .querit import QueritSdkProvider
25
27
 
28
+
26
29
  def load_providers(file_path='providers.yaml'):
27
- """
30
+ '''
28
31
  Parses the YAML configuration file and instantiates the appropriate provider classes.
29
-
32
+
30
33
  Args:
31
34
  file_path (str): Path to the providers configuration file.
32
-
35
+
33
36
  Returns:
34
37
  dict: A dictionary mapping provider names to their initialized instances.
35
- """
38
+ '''
36
39
  if not os.path.exists(file_path):
37
- print(f"Warning: Provider config file not found at {file_path}")
40
+ print(f'Warning: Provider config file not found at {file_path}')
38
41
  return {}
39
-
40
- with open(file_path, 'r', encoding='utf-8') as f:
42
+
43
+ with open(file_path, encoding='utf-8') as f:
41
44
  configs = yaml.safe_load(f)
42
45
 
43
46
  providers = {}