Spaces:
Build error
Build error
Ilia Tambovtsev commited on
Commit ·
ddf255f
1
Parent(s): b7dc0e7
refactor: change convenience functions
Browse files- src/chains/pipelines.py +31 -9
src/chains/pipelines.py
CHANGED
|
@@ -310,24 +310,47 @@ class PresentationPipeline(Chain):
|
|
| 310 |
|
| 311 |
|
| 312 |
def process_slide(
|
| 313 |
-
|
| 314 |
page_num: int,
|
| 315 |
-
llm:
|
| 316 |
-
vision_prompt: str =
|
| 317 |
-
dpi: int =
|
| 318 |
return_steps: bool = False
|
| 319 |
-
) ->
|
| 320 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
pipeline = SingleSlidePipeline(
|
| 322 |
llm=llm,
|
| 323 |
vision_prompt=vision_prompt,
|
| 324 |
dpi=dpi,
|
| 325 |
return_steps=return_steps
|
| 326 |
)
|
| 327 |
-
|
|
|
|
|
|
|
| 328 |
"pdf_path": pdf_path,
|
| 329 |
"page_num": page_num
|
| 330 |
})
|
|
|
|
| 331 |
|
| 332 |
|
| 333 |
def process_presentation(
|
|
@@ -335,8 +358,7 @@ def process_presentation(
|
|
| 335 |
llm: Optional[ChatOpenAI] = None,
|
| 336 |
vision_prompt: str = "Describe this slide in detail",
|
| 337 |
dpi: int = 144,
|
| 338 |
-
base_path: Optional[Path] = None
|
| 339 |
-
return_steps: bool = False
|
| 340 |
) -> PresentationAnalysis:
|
| 341 |
"""Convenience function for presentation processing
|
| 342 |
|
|
|
|
| 310 |
|
| 311 |
|
| 312 |
def process_slide(
|
| 313 |
+
path: Union[str, Path],
|
| 314 |
page_num: int,
|
| 315 |
+
llm: BaseLanguageModel,
|
| 316 |
+
vision_prompt: Optional[str] = None,
|
| 317 |
+
dpi: Optional[int] = None,
|
| 318 |
return_steps: bool = False
|
| 319 |
+
) -> Dict[str, Any]:
|
| 320 |
+
"""Query vision model and display results
|
| 321 |
+
|
| 322 |
+
Args:
|
| 323 |
+
path: PDF file path or substring of filename
|
| 324 |
+
page_num: Zero-based page number
|
| 325 |
+
llm: Language model with vision capabilities
|
| 326 |
+
vision_prompt: Optional custom prompt to use
|
| 327 |
+
|
| 328 |
+
Returns:
|
| 329 |
+
Dictionary with model outputs
|
| 330 |
+
"""
|
| 331 |
+
# Find file if path is substring
|
| 332 |
+
nav = Navigator()
|
| 333 |
+
if isinstance(path, str):
|
| 334 |
+
pdf_path = nav.find_file_by_substr(path)
|
| 335 |
+
if pdf_path is None:
|
| 336 |
+
raise ValueError(f"No PDF found matching '{path}'")
|
| 337 |
+
else:
|
| 338 |
+
pdf_path = Path(path)
|
| 339 |
+
|
| 340 |
+
# Create slide processing pipeline
|
| 341 |
pipeline = SingleSlidePipeline(
|
| 342 |
llm=llm,
|
| 343 |
vision_prompt=vision_prompt,
|
| 344 |
dpi=dpi,
|
| 345 |
return_steps=return_steps
|
| 346 |
)
|
| 347 |
+
|
| 348 |
+
# Process slide
|
| 349 |
+
result = pipeline.invoke({
|
| 350 |
"pdf_path": pdf_path,
|
| 351 |
"page_num": page_num
|
| 352 |
})
|
| 353 |
+
return result
|
| 354 |
|
| 355 |
|
| 356 |
def process_presentation(
|
|
|
|
| 358 |
llm: Optional[ChatOpenAI] = None,
|
| 359 |
vision_prompt: str = "Describe this slide in detail",
|
| 360 |
dpi: int = 144,
|
| 361 |
+
base_path: Optional[Path] = None
|
|
|
|
| 362 |
) -> PresentationAnalysis:
|
| 363 |
"""Convenience function for presentation processing
|
| 364 |
|