klaket 0.7.0__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.
- klaket-0.7.0/LICENSE +21 -0
- klaket-0.7.0/PKG-INFO +47 -0
- klaket-0.7.0/README.md +27 -0
- klaket-0.7.0/klaket/__init__.py +123 -0
- klaket-0.7.0/klaket/cli.py +141 -0
- klaket-0.7.0/klaket/langchain.py +78 -0
- klaket-0.7.0/klaket/llamaindex.py +60 -0
- klaket-0.7.0/klaket.egg-info/PKG-INFO +47 -0
- klaket-0.7.0/klaket.egg-info/SOURCES.txt +12 -0
- klaket-0.7.0/klaket.egg-info/dependency_links.txt +1 -0
- klaket-0.7.0/klaket.egg-info/entry_points.txt +2 -0
- klaket-0.7.0/klaket.egg-info/top_level.txt +1 -0
- klaket-0.7.0/pyproject.toml +32 -0
- klaket-0.7.0/setup.cfg +4 -0
klaket-0.7.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Klaket
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
klaket-0.7.0/PKG-INFO
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: klaket
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Summary: Python client + CLI for Klaket — turn any video into LLM-ready data
|
|
5
|
+
Author: Klaket
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/huseyinstif/klaket
|
|
8
|
+
Project-URL: Repository, https://github.com/huseyinstif/klaket
|
|
9
|
+
Project-URL: Issues, https://github.com/huseyinstif/klaket/issues
|
|
10
|
+
Keywords: video,llm,transcription,whisper,diarization,subtitles,mcp
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Multimedia :: Video
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# klaket (Python SDK)
|
|
22
|
+
|
|
23
|
+
Turn any video into LLM-ready data. Zero dependencies.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install klaket
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from klaket import Klaket
|
|
31
|
+
|
|
32
|
+
k = Klaket() # self-hosted; Klaket("https://api.klaket.dev", api_key="klk_...") for cloud
|
|
33
|
+
|
|
34
|
+
result = k.process(
|
|
35
|
+
"https://youtube.com/watch?v=...",
|
|
36
|
+
model="medium", # optional quality bump
|
|
37
|
+
prompt="Klaket, Docker, RAG", # proper-noun hints
|
|
38
|
+
num_speakers=2, # diarization hint
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
for seg in result["transcript"]:
|
|
42
|
+
print(f'[{seg["start"]:7.2f}] {seg.get("speaker", "")}: {seg["text"]}')
|
|
43
|
+
|
|
44
|
+
hits = k.search(result["id"], "docker compose command")
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
MIT licensed. Part of [Klaket](https://github.com/klaket/klaket).
|
klaket-0.7.0/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# klaket (Python SDK)
|
|
2
|
+
|
|
3
|
+
Turn any video into LLM-ready data. Zero dependencies.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install klaket
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from klaket import Klaket
|
|
11
|
+
|
|
12
|
+
k = Klaket() # self-hosted; Klaket("https://api.klaket.dev", api_key="klk_...") for cloud
|
|
13
|
+
|
|
14
|
+
result = k.process(
|
|
15
|
+
"https://youtube.com/watch?v=...",
|
|
16
|
+
model="medium", # optional quality bump
|
|
17
|
+
prompt="Klaket, Docker, RAG", # proper-noun hints
|
|
18
|
+
num_speakers=2, # diarization hint
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
for seg in result["transcript"]:
|
|
22
|
+
print(f'[{seg["start"]:7.2f}] {seg.get("speaker", "")}: {seg["text"]}')
|
|
23
|
+
|
|
24
|
+
hits = k.search(result["id"], "docker compose command")
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
MIT licensed. Part of [Klaket](https://github.com/klaket/klaket).
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Klaket Python SDK — turn any video into LLM-ready data.
|
|
2
|
+
|
|
3
|
+
Zero dependencies (stdlib urllib only).
|
|
4
|
+
|
|
5
|
+
from klaket import Klaket
|
|
6
|
+
|
|
7
|
+
k = Klaket() # self-hosted on localhost:8484
|
|
8
|
+
result = k.process("https://youtube.com/watch?v=...")
|
|
9
|
+
for seg in result["transcript"]:
|
|
10
|
+
print(seg["start"], seg.get("speaker", ""), seg["text"])
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import time
|
|
15
|
+
import urllib.error
|
|
16
|
+
import urllib.parse
|
|
17
|
+
import urllib.request
|
|
18
|
+
|
|
19
|
+
__version__ = "0.7.0"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class KlaketError(RuntimeError):
|
|
23
|
+
"""API-level error (validation, quota, auth, failed job…)."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Klaket:
|
|
27
|
+
def __init__(self, base_url: str = "http://localhost:8484", api_key: str = ""):
|
|
28
|
+
self.base_url = base_url.rstrip("/")
|
|
29
|
+
self.api_key = api_key
|
|
30
|
+
|
|
31
|
+
# --- core calls ---
|
|
32
|
+
|
|
33
|
+
def ingest(
|
|
34
|
+
self,
|
|
35
|
+
url: str,
|
|
36
|
+
*,
|
|
37
|
+
language: str = "auto",
|
|
38
|
+
model: str = "",
|
|
39
|
+
prompt: str = "",
|
|
40
|
+
num_speakers: int = 0,
|
|
41
|
+
translate_to: str = "",
|
|
42
|
+
webhook_url: str = "",
|
|
43
|
+
) -> str:
|
|
44
|
+
"""Queue a video; returns the job id."""
|
|
45
|
+
body = {"url": url, "language": language}
|
|
46
|
+
if model:
|
|
47
|
+
body["model"] = model
|
|
48
|
+
if prompt:
|
|
49
|
+
body["prompt"] = prompt
|
|
50
|
+
if num_speakers:
|
|
51
|
+
body["num_speakers"] = num_speakers
|
|
52
|
+
if translate_to:
|
|
53
|
+
body["translate_to"] = translate_to
|
|
54
|
+
if webhook_url:
|
|
55
|
+
body["webhook_url"] = webhook_url
|
|
56
|
+
return self._request("POST", "/v1/ingest", body)["id"]
|
|
57
|
+
|
|
58
|
+
def batch(self, urls: list, **options) -> list:
|
|
59
|
+
"""Queue many videos; returns the job ids."""
|
|
60
|
+
body = {"urls": urls, **{k: v for k, v in options.items() if v}}
|
|
61
|
+
return self._request("POST", "/v1/batch", body)["ids"]
|
|
62
|
+
|
|
63
|
+
def status(self, job_id: str) -> dict:
|
|
64
|
+
return self._request("GET", f"/v1/jobs/{job_id}")
|
|
65
|
+
|
|
66
|
+
def result(self, job_id: str) -> dict:
|
|
67
|
+
"""The full LLM-ready result (transcript, scenes, chapters…)."""
|
|
68
|
+
return self._request("GET", f"/v1/jobs/{job_id}/result")
|
|
69
|
+
|
|
70
|
+
def search(self, job_id: str, query: str) -> list:
|
|
71
|
+
"""Find moments inside a processed video."""
|
|
72
|
+
q = urllib.parse.quote(query)
|
|
73
|
+
return self._request("GET", f"/v1/jobs/{job_id}/search?q={q}")["hits"]
|
|
74
|
+
|
|
75
|
+
def delete(self, job_id: str) -> None:
|
|
76
|
+
self._request("DELETE", f"/v1/jobs/{job_id}")
|
|
77
|
+
|
|
78
|
+
def usage(self) -> dict:
|
|
79
|
+
return self._request("GET", "/v1/usage")
|
|
80
|
+
|
|
81
|
+
# --- conveniences ---
|
|
82
|
+
|
|
83
|
+
def wait(self, job_id: str, *, timeout: float = 1800, poll: float = 3) -> dict:
|
|
84
|
+
"""Block until the job finishes; raises KlaketError on failure/timeout."""
|
|
85
|
+
deadline = time.monotonic() + timeout
|
|
86
|
+
while time.monotonic() < deadline:
|
|
87
|
+
job = self.status(job_id)
|
|
88
|
+
if job["status"] == "done":
|
|
89
|
+
return job
|
|
90
|
+
if job["status"] == "failed":
|
|
91
|
+
raise KlaketError(f"job {job_id} failed: {job.get('error', '')}")
|
|
92
|
+
time.sleep(poll)
|
|
93
|
+
raise KlaketError(f"job {job_id} timed out after {timeout}s")
|
|
94
|
+
|
|
95
|
+
def process(self, url: str, **options) -> dict:
|
|
96
|
+
"""ingest + wait + result in one call."""
|
|
97
|
+
job_id = self.ingest(url, **options)
|
|
98
|
+
self.wait(job_id)
|
|
99
|
+
return self.result(job_id)
|
|
100
|
+
|
|
101
|
+
# --- plumbing ---
|
|
102
|
+
|
|
103
|
+
def _request(self, method: str, path: str, body: dict | None = None) -> dict:
|
|
104
|
+
req = urllib.request.Request(
|
|
105
|
+
self.base_url + path,
|
|
106
|
+
data=json.dumps(body).encode() if body is not None else None,
|
|
107
|
+
headers={
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
"User-Agent": f"klaket-python/{__version__}",
|
|
110
|
+
**({"Authorization": f"Bearer {self.api_key}"} if self.api_key else {}),
|
|
111
|
+
},
|
|
112
|
+
method=method,
|
|
113
|
+
)
|
|
114
|
+
try:
|
|
115
|
+
with urllib.request.urlopen(req, timeout=60) as res:
|
|
116
|
+
raw = res.read()
|
|
117
|
+
return json.loads(raw) if raw else {}
|
|
118
|
+
except urllib.error.HTTPError as exc:
|
|
119
|
+
try:
|
|
120
|
+
message = json.loads(exc.read()).get("error", str(exc))
|
|
121
|
+
except Exception:
|
|
122
|
+
message = str(exc)
|
|
123
|
+
raise KlaketError(message) from None
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""Klaket CLI — talk to a Klaket API from the terminal.
|
|
2
|
+
|
|
3
|
+
klaket ingest "https://youtube.com/watch?v=..." # queue, print job id
|
|
4
|
+
klaket ingest "https://..." --wait # queue + wait + print result JSON
|
|
5
|
+
klaket status <job-id>
|
|
6
|
+
klaket result <job-id>
|
|
7
|
+
klaket search <job-id> "docker compose"
|
|
8
|
+
klaket usage
|
|
9
|
+
|
|
10
|
+
Configuration: --api-url / KLAKET_API_URL (default http://localhost:8484),
|
|
11
|
+
--api-key / KLAKET_API_KEY (only needed against a cloud deployment).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
import sys
|
|
18
|
+
|
|
19
|
+
from . import Klaket, KlaketError, __version__
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _client(args: argparse.Namespace) -> Klaket:
|
|
23
|
+
return Klaket(base_url=args.api_url, api_key=args.api_key)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _dump(data) -> None:
|
|
27
|
+
json.dump(data, sys.stdout, indent=2, ensure_ascii=False)
|
|
28
|
+
sys.stdout.write("\n")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _cmd_ingest(args) -> None:
|
|
32
|
+
k = _client(args)
|
|
33
|
+
job_id = k.ingest(
|
|
34
|
+
args.url,
|
|
35
|
+
language=args.language,
|
|
36
|
+
model=args.model,
|
|
37
|
+
prompt=args.prompt,
|
|
38
|
+
num_speakers=args.num_speakers,
|
|
39
|
+
translate_to=args.translate_to,
|
|
40
|
+
webhook_url=args.webhook_url,
|
|
41
|
+
)
|
|
42
|
+
if args.wait:
|
|
43
|
+
print(f"queued {job_id} - waiting...", file=sys.stderr)
|
|
44
|
+
k.wait(job_id, timeout=args.timeout)
|
|
45
|
+
_dump(k.result(job_id))
|
|
46
|
+
else:
|
|
47
|
+
_dump({"id": job_id, "status": "queued"})
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _cmd_status(args) -> None:
|
|
51
|
+
_dump(_client(args).status(args.job_id))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _cmd_wait(args) -> None:
|
|
55
|
+
_dump(_client(args).wait(args.job_id, timeout=args.timeout))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _cmd_result(args) -> None:
|
|
59
|
+
_dump(_client(args).result(args.job_id))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _cmd_search(args) -> None:
|
|
63
|
+
_dump(_client(args).search(args.job_id, args.query))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _cmd_delete(args) -> None:
|
|
67
|
+
_client(args).delete(args.job_id)
|
|
68
|
+
print(f"deleted {args.job_id}", file=sys.stderr)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _cmd_usage(args) -> None:
|
|
72
|
+
_dump(_client(args).usage())
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def main(argv=None) -> int:
|
|
76
|
+
parser = argparse.ArgumentParser(
|
|
77
|
+
prog="klaket", description="Turn any video into LLM-ready data."
|
|
78
|
+
)
|
|
79
|
+
parser.add_argument("--version", action="version", version=f"klaket {__version__}")
|
|
80
|
+
parser.add_argument(
|
|
81
|
+
"--api-url",
|
|
82
|
+
default=os.environ.get("KLAKET_API_URL", "http://localhost:8484"),
|
|
83
|
+
help="Klaket API base URL (env KLAKET_API_URL)",
|
|
84
|
+
)
|
|
85
|
+
parser.add_argument(
|
|
86
|
+
"--api-key",
|
|
87
|
+
default=os.environ.get("KLAKET_API_KEY", ""),
|
|
88
|
+
help="API key for cloud mode (env KLAKET_API_KEY)",
|
|
89
|
+
)
|
|
90
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
91
|
+
|
|
92
|
+
p = sub.add_parser("ingest", help="queue a video (URL or worker-visible path)")
|
|
93
|
+
p.add_argument("url")
|
|
94
|
+
p.add_argument("--language", default="auto", help="ISO 639-1 hint (default: auto)")
|
|
95
|
+
p.add_argument("--model", default="", help="whisper model: tiny|base|small|medium|large-v3")
|
|
96
|
+
p.add_argument("--prompt", default="", help="context hint: proper nouns, jargon (max 500 chars)")
|
|
97
|
+
p.add_argument("--num-speakers", type=int, default=0, help="diarization hint (0 = auto)")
|
|
98
|
+
p.add_argument("--translate-to", default="", help="translate transcript to this ISO 639-1 language")
|
|
99
|
+
p.add_argument("--webhook-url", default="", help="POSTed on done/failed")
|
|
100
|
+
p.add_argument("--wait", action="store_true", help="wait and print the full result JSON")
|
|
101
|
+
p.add_argument("--timeout", type=float, default=1800, help="max seconds to wait (with --wait)")
|
|
102
|
+
p.set_defaults(func=_cmd_ingest)
|
|
103
|
+
|
|
104
|
+
p = sub.add_parser("status", help="show job status")
|
|
105
|
+
p.add_argument("job_id")
|
|
106
|
+
p.set_defaults(func=_cmd_status)
|
|
107
|
+
|
|
108
|
+
p = sub.add_parser("wait", help="block until a job finishes")
|
|
109
|
+
p.add_argument("job_id")
|
|
110
|
+
p.add_argument("--timeout", type=float, default=1800)
|
|
111
|
+
p.set_defaults(func=_cmd_wait)
|
|
112
|
+
|
|
113
|
+
p = sub.add_parser("result", help="print the LLM-ready result JSON")
|
|
114
|
+
p.add_argument("job_id")
|
|
115
|
+
p.set_defaults(func=_cmd_result)
|
|
116
|
+
|
|
117
|
+
p = sub.add_parser("search", help="find moments inside a processed video")
|
|
118
|
+
p.add_argument("job_id")
|
|
119
|
+
p.add_argument("query")
|
|
120
|
+
p.set_defaults(func=_cmd_search)
|
|
121
|
+
|
|
122
|
+
p = sub.add_parser("delete", help="delete a job and its artifacts")
|
|
123
|
+
p.add_argument("job_id")
|
|
124
|
+
p.set_defaults(func=_cmd_delete)
|
|
125
|
+
|
|
126
|
+
p = sub.add_parser("usage", help="show this month's video-minute usage")
|
|
127
|
+
p.set_defaults(func=_cmd_usage)
|
|
128
|
+
|
|
129
|
+
args = parser.parse_args(argv)
|
|
130
|
+
try:
|
|
131
|
+
args.func(args)
|
|
132
|
+
except KlaketError as exc:
|
|
133
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
134
|
+
return 1
|
|
135
|
+
except KeyboardInterrupt:
|
|
136
|
+
return 130
|
|
137
|
+
return 0
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if __name__ == "__main__":
|
|
141
|
+
sys.exit(main())
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""LangChain document loader for Klaket.
|
|
2
|
+
|
|
3
|
+
pip install klaket langchain-core
|
|
4
|
+
|
|
5
|
+
from klaket.langchain import KlaketLoader
|
|
6
|
+
|
|
7
|
+
docs = KlaketLoader("https://youtube.com/watch?v=…").load()
|
|
8
|
+
# or from a finished job: KlaketLoader("1f3a9c04d2e88b17").load()
|
|
9
|
+
|
|
10
|
+
Each Document corresponds to a chapter (by="chapter", the default) or a
|
|
11
|
+
single transcript segment (by="segment"); metadata carries the video title,
|
|
12
|
+
time range, language, and speaker.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import re
|
|
16
|
+
from typing import Iterator
|
|
17
|
+
|
|
18
|
+
from . import Klaket
|
|
19
|
+
|
|
20
|
+
_JOB_ID = re.compile(r"^[0-9a-f]{16}$")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class KlaketLoader:
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
source: str,
|
|
27
|
+
*,
|
|
28
|
+
base_url: str = "http://localhost:8484",
|
|
29
|
+
api_key: str = "",
|
|
30
|
+
by: str = "chapter",
|
|
31
|
+
**ingest_options,
|
|
32
|
+
):
|
|
33
|
+
if by not in ("chapter", "segment"):
|
|
34
|
+
raise ValueError('by must be "chapter" or "segment"')
|
|
35
|
+
self.source = source
|
|
36
|
+
self.by = by
|
|
37
|
+
self.ingest_options = ingest_options
|
|
38
|
+
self.client = Klaket(base_url, api_key)
|
|
39
|
+
|
|
40
|
+
def _result(self) -> dict:
|
|
41
|
+
if _JOB_ID.match(self.source):
|
|
42
|
+
return self.client.result(self.source)
|
|
43
|
+
return self.client.process(self.source, **self.ingest_options)
|
|
44
|
+
|
|
45
|
+
def lazy_load(self) -> Iterator:
|
|
46
|
+
try:
|
|
47
|
+
from langchain_core.documents import Document
|
|
48
|
+
except ImportError as exc: # pragma: no cover
|
|
49
|
+
raise ImportError("KlaketLoader requires langchain-core: pip install langchain-core") from exc
|
|
50
|
+
|
|
51
|
+
result = self._result()
|
|
52
|
+
base_meta = {
|
|
53
|
+
"source": result.get("url", self.source),
|
|
54
|
+
"title": result.get("title", ""),
|
|
55
|
+
"language": result.get("language", ""),
|
|
56
|
+
"klaket_job_id": result.get("id", ""),
|
|
57
|
+
}
|
|
58
|
+
if self.by == "segment":
|
|
59
|
+
for seg in result["transcript"]:
|
|
60
|
+
yield Document(
|
|
61
|
+
page_content=seg["text"],
|
|
62
|
+
metadata={**base_meta, "start": seg["start"], "end": seg["end"],
|
|
63
|
+
"speaker": seg.get("speaker", "")},
|
|
64
|
+
)
|
|
65
|
+
return
|
|
66
|
+
for chapter in result.get("chapters", []):
|
|
67
|
+
texts = [
|
|
68
|
+
seg["text"] for seg in result["transcript"]
|
|
69
|
+
if seg["start"] < chapter["end"] and seg["end"] > chapter["start"]
|
|
70
|
+
]
|
|
71
|
+
yield Document(
|
|
72
|
+
page_content=" ".join(texts) or chapter["title"],
|
|
73
|
+
metadata={**base_meta, "chapter": chapter["title"],
|
|
74
|
+
"start": chapter["start"], "end": chapter["end"]},
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
def load(self) -> list:
|
|
78
|
+
return list(self.lazy_load())
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""LlamaIndex reader for Klaket.
|
|
2
|
+
|
|
3
|
+
pip install klaket llama-index-core
|
|
4
|
+
|
|
5
|
+
from klaket.llamaindex import KlaketReader
|
|
6
|
+
|
|
7
|
+
docs = KlaketReader().load_data("https://youtube.com/watch?v=…")
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
from . import Klaket
|
|
13
|
+
|
|
14
|
+
_JOB_ID = re.compile(r"^[0-9a-f]{16}$")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class KlaketReader:
|
|
18
|
+
def __init__(self, base_url: str = "http://localhost:8484", api_key: str = "", by: str = "chapter"):
|
|
19
|
+
if by not in ("chapter", "segment"):
|
|
20
|
+
raise ValueError('by must be "chapter" or "segment"')
|
|
21
|
+
self.by = by
|
|
22
|
+
self.client = Klaket(base_url, api_key)
|
|
23
|
+
|
|
24
|
+
def load_data(self, source: str, **ingest_options) -> list:
|
|
25
|
+
try:
|
|
26
|
+
from llama_index.core.schema import Document
|
|
27
|
+
except ImportError as exc: # pragma: no cover
|
|
28
|
+
raise ImportError("KlaketReader requires llama-index-core: pip install llama-index-core") from exc
|
|
29
|
+
|
|
30
|
+
result = (
|
|
31
|
+
self.client.result(source)
|
|
32
|
+
if _JOB_ID.match(source)
|
|
33
|
+
else self.client.process(source, **ingest_options)
|
|
34
|
+
)
|
|
35
|
+
base_meta = {
|
|
36
|
+
"source": result.get("url", source),
|
|
37
|
+
"title": result.get("title", ""),
|
|
38
|
+
"language": result.get("language", ""),
|
|
39
|
+
"klaket_job_id": result.get("id", ""),
|
|
40
|
+
}
|
|
41
|
+
docs = []
|
|
42
|
+
if self.by == "segment":
|
|
43
|
+
for seg in result["transcript"]:
|
|
44
|
+
docs.append(Document(
|
|
45
|
+
text=seg["text"],
|
|
46
|
+
metadata={**base_meta, "start": seg["start"], "end": seg["end"],
|
|
47
|
+
"speaker": seg.get("speaker", "")},
|
|
48
|
+
))
|
|
49
|
+
return docs
|
|
50
|
+
for chapter in result.get("chapters", []):
|
|
51
|
+
texts = [
|
|
52
|
+
seg["text"] for seg in result["transcript"]
|
|
53
|
+
if seg["start"] < chapter["end"] and seg["end"] > chapter["start"]
|
|
54
|
+
]
|
|
55
|
+
docs.append(Document(
|
|
56
|
+
text=" ".join(texts) or chapter["title"],
|
|
57
|
+
metadata={**base_meta, "chapter": chapter["title"],
|
|
58
|
+
"start": chapter["start"], "end": chapter["end"]},
|
|
59
|
+
))
|
|
60
|
+
return docs
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: klaket
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Summary: Python client + CLI for Klaket — turn any video into LLM-ready data
|
|
5
|
+
Author: Klaket
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/huseyinstif/klaket
|
|
8
|
+
Project-URL: Repository, https://github.com/huseyinstif/klaket
|
|
9
|
+
Project-URL: Issues, https://github.com/huseyinstif/klaket/issues
|
|
10
|
+
Keywords: video,llm,transcription,whisper,diarization,subtitles,mcp
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Multimedia :: Video
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# klaket (Python SDK)
|
|
22
|
+
|
|
23
|
+
Turn any video into LLM-ready data. Zero dependencies.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install klaket
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from klaket import Klaket
|
|
31
|
+
|
|
32
|
+
k = Klaket() # self-hosted; Klaket("https://api.klaket.dev", api_key="klk_...") for cloud
|
|
33
|
+
|
|
34
|
+
result = k.process(
|
|
35
|
+
"https://youtube.com/watch?v=...",
|
|
36
|
+
model="medium", # optional quality bump
|
|
37
|
+
prompt="Klaket, Docker, RAG", # proper-noun hints
|
|
38
|
+
num_speakers=2, # diarization hint
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
for seg in result["transcript"]:
|
|
42
|
+
print(f'[{seg["start"]:7.2f}] {seg.get("speaker", "")}: {seg["text"]}')
|
|
43
|
+
|
|
44
|
+
hits = k.search(result["id"], "docker compose command")
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
MIT licensed. Part of [Klaket](https://github.com/klaket/klaket).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
klaket/__init__.py
|
|
5
|
+
klaket/cli.py
|
|
6
|
+
klaket/langchain.py
|
|
7
|
+
klaket/llamaindex.py
|
|
8
|
+
klaket.egg-info/PKG-INFO
|
|
9
|
+
klaket.egg-info/SOURCES.txt
|
|
10
|
+
klaket.egg-info/dependency_links.txt
|
|
11
|
+
klaket.egg-info/entry_points.txt
|
|
12
|
+
klaket.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
klaket
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "klaket"
|
|
3
|
+
version = "0.7.0"
|
|
4
|
+
description = "Python client + CLI for Klaket — turn any video into LLM-ready data"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.9"
|
|
9
|
+
keywords = ["video", "llm", "transcription", "whisper", "diarization", "subtitles", "mcp"]
|
|
10
|
+
authors = [{ name = "Klaket" }]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Topic :: Multimedia :: Video",
|
|
16
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/huseyinstif/klaket"
|
|
21
|
+
Repository = "https://github.com/huseyinstif/klaket"
|
|
22
|
+
Issues = "https://github.com/huseyinstif/klaket/issues"
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
klaket = "klaket.cli:main"
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["setuptools>=77"]
|
|
29
|
+
build-backend = "setuptools.build_meta"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.packages.find]
|
|
32
|
+
include = ["klaket*"]
|
klaket-0.7.0/setup.cfg
ADDED