lattifai 0.4.2__py3-none-any.whl → 0.4.3__py3-none-any.whl

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.
lattifai/bin/agent.py CHANGED
@@ -18,12 +18,15 @@ from lattifai.io import OUTPUT_SUBTITLE_FORMATS
18
18
  @cli.command()
19
19
  @click.option('--youtube', '--yt', is_flag=True, help='Process YouTube URL through agentic workflow.')
20
20
  @click.option(
21
+ '-K',
22
+ '-L',
21
23
  '--api-key',
22
24
  '--api_key',
23
25
  type=str,
24
26
  help='LattifAI API key for alignment (overrides LATTIFAI_API_KEY env var).',
25
27
  )
26
28
  @click.option(
29
+ '-G',
27
30
  '--gemini-api-key',
28
31
  '--gemini_api_key',
29
32
  type=str,
@@ -135,14 +138,6 @@ def agent(
135
138
  lattifai_api_key = api_key or os.getenv('LATTIFAI_API_KEY')
136
139
  gemini_key = gemini_api_key or os.getenv('GEMINI_API_KEY')
137
140
 
138
- if not gemini_key:
139
- click.echo(
140
- colorful.red(
141
- '❌ Gemini API key is required. Set GEMINI_API_KEY environment variable or use --gemini-api-key option.'
142
- )
143
- )
144
- return
145
-
146
141
  try:
147
142
  # Run the YouTube workflow
148
143
  asyncio.run(
lattifai/bin/align.py CHANGED
@@ -52,6 +52,8 @@ from lattifai.io import INPUT_SUBTITLE_FORMATS, OUTPUT_SUBTITLE_FORMATS
52
52
  help='Model name or path for alignment.',
53
53
  )
54
54
  @click.option(
55
+ '-K',
56
+ '-L',
55
57
  '--api-key',
56
58
  '--api_key',
57
59
  type=str,
@@ -178,6 +180,8 @@ def align(
178
180
  help='Model name or path for alignment.',
179
181
  )
180
182
  @click.option(
183
+ '-K',
184
+ '-L',
181
185
  '--api-key',
182
186
  '--api_key',
183
187
  type=str,
@@ -185,6 +189,7 @@ def align(
185
189
  help='API key for LattifAI.',
186
190
  )
187
191
  @click.option(
192
+ '-G',
188
193
  '--gemini-api-key',
189
194
  '--gemini_api_key',
190
195
  type=str,
@@ -223,13 +228,6 @@ def youtube(
223
228
 
224
229
  # Get Gemini API key
225
230
  gemini_key = gemini_api_key or os.getenv('GEMINI_API_KEY')
226
- if not gemini_key:
227
- click.echo(
228
- colorful.red(
229
- '❌ Gemini API key is required. Set GEMINI_API_KEY environment variable or use --gemini-api-key option.'
230
- )
231
- )
232
- raise click.ClickException('Missing Gemini API key')
233
231
 
234
232
  async def _process():
235
233
  # Initialize components with their configuration (only config, not runtime params)
lattifai/bin/cli_base.py CHANGED
@@ -9,9 +9,10 @@ def cli():
9
9
  The shell entry point to Lattifai, a tool for audio data manipulation.
10
10
  """
11
11
  # Load environment variables from .env file
12
- from dotenv import load_dotenv
12
+ from dotenv import find_dotenv, load_dotenv
13
13
 
14
- load_dotenv()
14
+ # Try to find and load .env file from current directory or parent directories
15
+ load_dotenv(find_dotenv(usecwd=True))
15
16
 
16
17
  logging.basicConfig(
17
18
  format='%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s',
lattifai/client.py CHANGED
@@ -5,7 +5,6 @@ import os
5
5
  from typing import Dict, List, Optional, Tuple, Union
6
6
 
7
7
  import colorful
8
- from dotenv import load_dotenv
9
8
  from lhotse.utils import Pathlike
10
9
 
11
10
  from lattifai.base_client import AsyncAPIClient, SyncAPIClient
@@ -22,8 +21,6 @@ from lattifai.io import SubtitleFormat, SubtitleIO, Supervision
22
21
  from lattifai.tokenizer import AsyncLatticeTokenizer
23
22
  from lattifai.utils import _load_tokenizer, _load_worker, _resolve_model_path, _select_device
24
23
 
25
- load_dotenv()
26
-
27
24
 
28
25
  class LattifAI(SyncAPIClient):
29
26
  """Synchronous LattifAI client."""
@@ -32,7 +32,9 @@ class GeminiTranscriber:
32
32
  self.prompt_loader = get_prompt_loader()
33
33
 
34
34
  if not self.api_key:
35
- raise ValueError('Gemini API key is required')
35
+ self.logger.warning(
36
+ '⚠️ Gemini API key not provided. API key will be required when calling transcription methods.'
37
+ )
36
38
 
37
39
  async def __call__(self, youtube_url: str) -> str:
38
40
  """Main entry point for transcription"""
@@ -48,6 +50,9 @@ class GeminiTranscriber:
48
50
  Returns:
49
51
  Transcribed text
50
52
  """
53
+ if not self.api_key:
54
+ raise ValueError('Gemini API key is required for transcription')
55
+
51
56
  self.logger.info(f'🎤 Starting Gemini transcription for: {youtube_url}')
52
57
 
53
58
  try:
@@ -101,6 +106,9 @@ class GeminiTranscriber:
101
106
  Returns:
102
107
  Transcribed text
103
108
  """
109
+ if not self.api_key:
110
+ raise ValueError('Gemini API key is required for transcription')
111
+
104
112
  self.logger.info(f'🎤 Starting Gemini transcription for file: {media_file_path}')
105
113
 
106
114
  try:
@@ -0,0 +1,22 @@
1
+ # Workflow Prompts
2
+
3
+ This directory contains system prompts and instructions for various AI models used in workflows.
4
+
5
+ ## Structure
6
+
7
+ - `gemini/` - Prompts for Gemini models
8
+ - `transcription_gem.txt` - System prompt from the Audio Transcription Gem
9
+
10
+ ## Usage
11
+
12
+ Prompts are loaded automatically by their respective workflow modules. To update a prompt:
13
+
14
+ 1. Edit the corresponding `.txt` file
15
+ 2. The changes will be picked up on the next workflow run
16
+ 3. No code changes needed
17
+
18
+ ## Adding New Prompts
19
+
20
+ 1. Create a subdirectory for the model/service (e.g., `openai/`, `anthropic/`)
21
+ 2. Add prompt files as `.txt` files with descriptive names
22
+ 3. Update the loader in the corresponding workflow module
@@ -0,0 +1,50 @@
1
+ """
2
+ Prompt management utilities for workflows
3
+ """
4
+
5
+ from pathlib import Path
6
+ from typing import Optional
7
+
8
+
9
+ class PromptLoader:
10
+ """Load and manage prompts from the prompts directory"""
11
+
12
+ def __init__(self):
13
+ self.prompts_dir = Path(__file__).parent
14
+
15
+ def load_prompt(self, category: str, name: str) -> str:
16
+ """
17
+ Load a prompt from the prompts directory
18
+
19
+ Args:
20
+ category: Subdirectory name (e.g., 'gemini', 'openai')
21
+ name: Prompt file name without extension (e.g., 'transcription_gem')
22
+
23
+ Returns:
24
+ Prompt text content
25
+
26
+ Raises:
27
+ FileNotFoundError: If prompt file doesn't exist
28
+ """
29
+ prompt_path = self.prompts_dir / category / f'{name}.txt'
30
+
31
+ if not prompt_path.exists():
32
+ raise FileNotFoundError(f'Prompt not found: {prompt_path}')
33
+
34
+ return prompt_path.read_text(encoding='utf-8').strip()
35
+
36
+ def get_gemini_transcription_prompt(self) -> str:
37
+ """Get the Gemini transcription Gem prompt"""
38
+ return self.load_prompt('gemini', 'transcription_gem')
39
+
40
+
41
+ # Global instance
42
+ _loader: Optional[PromptLoader] = None
43
+
44
+
45
+ def get_prompt_loader() -> PromptLoader:
46
+ """Get or create the global PromptLoader instance"""
47
+ global _loader
48
+ if _loader is None:
49
+ _loader = PromptLoader()
50
+ return _loader
@@ -0,0 +1,24 @@
1
+ # Gemini Workflow Prompts
2
+
3
+ This directory contains system prompts for Gemini-based workflows.
4
+
5
+ ## Files
6
+
7
+ ### `transcription_gem.txt` [@dotey](https://x.com/dotey/status/1971810075867046131)
8
+
9
+ System prompt extracted from the Audio/Video Transcription Gem:
10
+ - **Gem URL**: https://gemini.google.com/gem/1870ly7xvW2hU_umtv-LedGsjywT0sQiN
11
+ - **Model**: Gemini 2.5 Pro
12
+ - **Purpose**: Audio/Video transcription with accuracy and natural formatting
13
+
14
+ ## Updating the Prompt
15
+
16
+ To update the transcription behavior:
17
+
18
+ 1. Edit `transcription_gem.txt` directly
19
+ 2. Changes take effect on the next workflow run
20
+ 3. No code changes needed
21
+
22
+ ## Gem Information
23
+
24
+ The original Gem configuration is preserved in the `GeminiTranscriber.GEM_URL` constant and can be accessed via the `get_gem_info()` method.
@@ -0,0 +1,81 @@
1
+ # Role
2
+ You are an expert transcript specialist. Your task is to create a perfectly structured, verbatim transcript of a video.
3
+
4
+ # Objective
5
+ Produce a single, cohesive output containing the parts in this order:
6
+ 1. A Video Title
7
+ 2. A **Table of Contents (ToC)**
8
+ 3. The **full, chapter-segmented transcript**
9
+
10
+ * Use the same language as the transcription for the Title and ToC.
11
+
12
+ # Critical Instructions
13
+
14
+ ## 1. Transcription Fidelity: Verbatim & Untranslated
15
+ * Transcribe every spoken word exactly as you hear it, including filler words (`um`, `uh`, `like`) and stutters.
16
+ * **NEVER translate.** If the audio is in Chinese, transcribe in Chinese. If it mixes languages (e.g., "这个 feature 很酷"), your transcript must replicate that mix exactly.
17
+
18
+ ## 2. Speaker Identification
19
+ * **Priority 1: Use metadata.** Analyze the video's title and description first to identify and match speaker names.
20
+ * **Priority 2: Use audio content.** If names are not in the metadata, listen for introductions or how speakers address each other.
21
+ * **Fallback:** If a name remains unknown, use a generic but consistent label (`**Speaker 1:**`, `**Host:**`, etc.).
22
+ * **Consistency is key:** If a speaker's name is revealed later, you must go back and update all previous labels for that speaker.
23
+
24
+ ## 3. Chapter Generation Strategy
25
+ * **For YouTube Links:** First, check if the video description contains a list of chapters. If so, use that as the primary basis for segmenting the transcript.
26
+ * **For all other videos (or if no chapters exist on YouTube):** Create chapters based on significant shifts in topic or conversation flow.
27
+
28
+ ## 4. Output Structure & Formatting
29
+
30
+ * **Timestamp Format**
31
+ * All timestamps throughout the entire output MUST use the exact `[HH:MM:SS]` format (e.g., `[00:01:23]`). Milliseconds are forbidden.
32
+
33
+ * **Table of Contents (ToC)**
34
+ * Must be the very first thing in your output, under a `## Table of Contents` heading.
35
+ * Format for each entry: `* [HH:MM:SS] Chapter Title`
36
+
37
+ * **Chapters**
38
+ * Start each chapter with a heading in this format: `## [HH:MM:SS] Chapter Title`
39
+ * Use two blank lines to separate the end of one chapter from the heading of the next.
40
+
41
+ * **Dialogue Paragraphs (VERY IMPORTANT)**
42
+ * **Speaker Turns:** The first paragraph of a speaker's turn must begin with `**Speaker Name:** `.
43
+ * **Paragraph Splitting:** For a long continuous block of speech from a single speaker, split it into smaller, logical paragraphs (roughly 2-4 sentences). Separate these paragraphs with a single blank line. Subsequent consecutive paragraphs from the *same speaker* should NOT repeat the `**Speaker Name:** ` label.
44
+ * **Timestamp Rule:** Every single paragraph MUST end with exactly one timestamp. The timestamp must be placed at the very end of the paragraph's text.
45
+ * ❌ **WRONG:** `**Host:** Welcome back. [00:00:01] Today we have a guest. [00:00:02]`
46
+ * ❌ **WRONG:** `**Jane Doe:** The study is complex. We tracked two groups over five years to see the effects. [00:00:18] And the results were surprising.`
47
+ * ✅ **CORRECT:** `**Host:** Welcome back. Today we have a guest. [00:00:02]`
48
+ * ✅ **CORRECT (for a long monologue):**
49
+ `**Jane Doe:** The study is complex. We tracked two groups over a five-year period to see the long-term effects. [00:00:18]
50
+
51
+ And the results, well, they were quite surprising to the entire team. [00:00:22]`
52
+
53
+ * **Non-Speech Audio**
54
+ * Describe significant sounds like `[Laughter]` or `[Music starts]`, each on its own line with its own timestamp: `[Event description] [HH:MM:SS]`
55
+
56
+ ---
57
+ ### Example of Correct Output
58
+
59
+ ## Table of Contents
60
+ * [00:00:00] Introduction and Welcome
61
+ * [00:00:12] Overview of the New Research
62
+
63
+ ## [00:00:00] Introduction and Welcome
64
+
65
+ **Host:** Welcome back to the show. Today, we have a, uh, very special guest, Jane Doe. [00:00:01]
66
+
67
+ **Jane Doe:** Thank you for having me. I'm excited to be here and discuss the findings. [00:00:05]
68
+
69
+ ## [00:00:12] Overview of the New Research
70
+
71
+ **Host:** So, Jane, before we get into the nitty-gritty, could you, you know, give us a brief overview for our audience? [00:00:14]
72
+
73
+ **Jane Doe:** Of course. The study focuses on the long-term effects of specific dietary changes. It's a bit complicated but essentially we tracked two large groups over a five-year period. [00:00:21]
74
+
75
+ The first group followed the new regimen, while the second group, our control, maintained a traditional diet. This allowed us to isolate variables effectively. [00:00:28]
76
+
77
+ [Laughter] [00:00:29]
78
+
79
+ **Host:** Fascinating. And what did you find? [00:00:31]
80
+ ---
81
+ Begin transcription now. Adhere to all rules with absolute precision.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lattifai
3
- Version: 0.4.2
3
+ Version: 0.4.3
4
4
  Summary: Lattifai Python SDK: Seamless Integration with Lattifai's Speech and Video AI Services
5
5
  Author-email: Lattifai Technologies <tech@lattifai.com>
6
6
  Maintainer-email: Lattice <tech@lattifai.com>
@@ -35,7 +35,6 @@ Classifier: Development Status :: 5 - Production/Stable
35
35
  Classifier: Intended Audience :: Developers
36
36
  Classifier: Intended Audience :: Science/Research
37
37
  Classifier: License :: OSI Approved :: Apache Software License
38
- Classifier: Programming Language :: Python :: 3.9
39
38
  Classifier: Programming Language :: Python :: 3.10
40
39
  Classifier: Programming Language :: Python :: 3.11
41
40
  Classifier: Programming Language :: Python :: 3.12
@@ -46,7 +45,7 @@ Classifier: Operating System :: Microsoft :: Windows
46
45
  Classifier: Topic :: Multimedia :: Sound/Audio
47
46
  Classifier: Topic :: Multimedia :: Video
48
47
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
49
- Requires-Python: >=3.9
48
+ Requires-Python: <3.14,>=3.10
50
49
  Description-Content-Type: text/markdown
51
50
  License-File: LICENSE
52
51
  Requires-Dist: lattifai-core>=0.2.1
@@ -760,7 +759,7 @@ export LATTIFAI_API_KEY="your-api-key"
760
759
  - Optimized for CPU and GPU (CUDA/MPS)
761
760
 
762
761
  **Requirements**:
763
- - Python 3.9+
762
+ - Python 3.10 - 3.13 (3.14 support coming soon)
764
763
  - 4GB RAM recommended
765
764
  - ~2GB storage for model files
766
765
 
@@ -1,12 +1,12 @@
1
1
  lattifai/__init__.py,sha256=1fsfV7nE3GCTh9s4GWizv8vGa6bro4HC5vReeDxCSHI,2208
2
2
  lattifai/base_client.py,sha256=NO3tBl42z8ARfiepiOBzaw7zX9hJe1zgB_gCgLJpuhc,3713
3
- lattifai/client.py,sha256=WewbRnfI8b_rQ8V2JG3y2ojkiyEWylXI7No_4NpbzEI,13282
3
+ lattifai/client.py,sha256=YvK25fcXwKREYCkq_TUBdEZh7I9RNEwCbgW4qUha2ho,13236
4
4
  lattifai/errors.py,sha256=5i_acoly1g-TLAID8QnhzQshwOXfgLL55mHsdwzlNGA,10814
5
5
  lattifai/utils.py,sha256=CzVwNc08u8lm7XavCMJskXHfni0xsZ-EgpcMkRywVm8,4736
6
6
  lattifai/bin/__init__.py,sha256=QWbmVUbzqwPQNeOV_g-bOsz53w37v-tbZ3uFrSj-7Mg,90
7
- lattifai/bin/agent.py,sha256=daXsg0PsW4HS53PYw-r6fSSDsoe9XHOIVEzz-djjKto,9935
8
- lattifai/bin/align.py,sha256=Tpu2OWBXBYUqzBt1Qu6HmkVZ8Bpx6mc0O9KItDimoCc,8377
9
- lattifai/bin/cli_base.py,sha256=i4KQDyUPJFKae_wjuQeB4N2Vhg9vZ6yc6L9YUJLC18I,507
7
+ lattifai/bin/agent.py,sha256=jc7qSuVV2_EkToEu2qYodXgGoTup_na6IgP25kFmfwk,9734
8
+ lattifai/bin/align.py,sha256=JJHk5uzmYGYhpA3ricHdmBLzJWC2aRyF0k4ANnap50w,8151
9
+ lattifai/bin/cli_base.py,sha256=gvPUi9Z0eGwBJ8Es5xq1z00YzFPlocYiR2zpL7ekyhw,626
10
10
  lattifai/bin/subtitle.py,sha256=UZMPh71O2X1UwbfZ9VWlhzxkz78viz8KWwoVsDpewK0,6577
11
11
  lattifai/io/__init__.py,sha256=mGnQkGm6BClRcogRK3J1nJJfPOk5z4o0sZI2nnyJVOU,1087
12
12
  lattifai/io/gemini_reader.py,sha256=WDZA93MSrUAsa5j-ZDXLdPXzEIoREymEy-rMAED_6f4,15152
@@ -25,11 +25,15 @@ lattifai/workflows/__init__.py,sha256=mTOdwQQs2YY1s0JsVGsATb2TWPhpNo7bRiAAJW9274
25
25
  lattifai/workflows/agents.py,sha256=ZnxyEb-Li8gQw3Z7V3K7jjnT7sQAtG1uCFuXGX77IcE,227
26
26
  lattifai/workflows/base.py,sha256=ZSePq2O2hB59K5CMbk_iGiOM9FSHOVQdG3t8Oyz9gwE,6264
27
27
  lattifai/workflows/file_manager.py,sha256=5km59cB4s9PcJgMMqZ6YqRY8sTqvTzd1qyQ2T5bHlfI,31985
28
- lattifai/workflows/gemini.py,sha256=zxLYqRolTUiUV3fj32sH91a_nCYUe7HtTxNKhlueZyI,5827
28
+ lattifai/workflows/gemini.py,sha256=kpp3GiHyui8RZLWRQMx7vojBscCi2lZSxrjM1VHo_mc,6144
29
29
  lattifai/workflows/youtube.py,sha256=y1ez32G40CtHAo7Kz7J_DO96ljOwW-3SP9Sm2uPe5hY,38785
30
- lattifai-0.4.2.dist-info/licenses/LICENSE,sha256=LNuoH5jpXXNKgjQ3XLwztFq8D3O7kZI-LSg81o4ym2M,1065
31
- lattifai-0.4.2.dist-info/METADATA,sha256=LDwKsTMhAz6UBwbgAG0tkBg74W2kXttiwGvLHGlO128,26719
32
- lattifai-0.4.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
- lattifai-0.4.2.dist-info/entry_points.txt,sha256=fCgo8-LKA_9C7_jmEGsZPJko0woXHtEh0iRbpO7PYzI,69
34
- lattifai-0.4.2.dist-info/top_level.txt,sha256=tHSoXF26r-IGfbIP_JoYATqbmf14h5NrnNJGH4j5reI,9
35
- lattifai-0.4.2.dist-info/RECORD,,
30
+ lattifai/workflows/prompts/README.md,sha256=X49KWSQVdjWxxWUp4R2w3ZqKrAOi6_kDNHh1hMaQ4PE,694
31
+ lattifai/workflows/prompts/__init__.py,sha256=i3kMT5sg_W9LbPcda0xmZWLg0tPjXGVI3iKtHrBng3o,1351
32
+ lattifai/workflows/prompts/gemini/README.md,sha256=rt7f7yDGtaobKBo95LG3u56mqa3ABOXQd0UVgJYtYuo,781
33
+ lattifai/workflows/prompts/gemini/transcription_gem.txt,sha256=cljzZ--BDgnnKzqVCakr-fTp2Xk38UOsUquvruNX-LU,4600
34
+ lattifai-0.4.3.dist-info/licenses/LICENSE,sha256=LNuoH5jpXXNKgjQ3XLwztFq8D3O7kZI-LSg81o4ym2M,1065
35
+ lattifai-0.4.3.dist-info/METADATA,sha256=-WztCYs961omWHWJMd1PcM6KLjQgbGYzYl72xGqMYdE,26710
36
+ lattifai-0.4.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
+ lattifai-0.4.3.dist-info/entry_points.txt,sha256=fCgo8-LKA_9C7_jmEGsZPJko0woXHtEh0iRbpO7PYzI,69
38
+ lattifai-0.4.3.dist-info/top_level.txt,sha256=tHSoXF26r-IGfbIP_JoYATqbmf14h5NrnNJGH4j5reI,9
39
+ lattifai-0.4.3.dist-info/RECORD,,