Spaces:
Build error
Build error
Ilia Tambovtsev commited on
Commit ·
e03b33d
1
Parent(s): a253052
fix: resolve imports
Browse files- src/__init__.py +2 -1
- src/chains/chains.py +1 -1
- src/chains/pipelines.py +1 -1
- src/config/navigator.py +4 -1
- src/testing_utils/__init__.py +0 -1
- src/testing_utils/display.py +0 -73
src/__init__.py
CHANGED
|
@@ -3,7 +3,8 @@ from src.config import (
|
|
| 3 |
Config,
|
| 4 |
ModelConfig,
|
| 5 |
Navigator,
|
| 6 |
-
MultilineWrapper
|
|
|
|
| 7 |
)
|
| 8 |
|
| 9 |
from src.chains import (
|
|
|
|
| 3 |
Config,
|
| 4 |
ModelConfig,
|
| 5 |
Navigator,
|
| 6 |
+
MultilineWrapper,
|
| 7 |
+
query_and_display,
|
| 8 |
)
|
| 9 |
|
| 10 |
from src.chains import (
|
src/chains/chains.py
CHANGED
|
@@ -17,7 +17,7 @@ from io import BytesIO
|
|
| 17 |
from PIL import Image
|
| 18 |
from src.chains.chain_funcs import get_param_or_default
|
| 19 |
|
| 20 |
-
from src.config import Navigator
|
| 21 |
from src.processing import page2image, image2base64
|
| 22 |
|
| 23 |
logger = logging.getLogger(__name__)
|
|
|
|
| 17 |
from PIL import Image
|
| 18 |
from src.chains.chain_funcs import get_param_or_default
|
| 19 |
|
| 20 |
+
from src.config.navigator import Navigator
|
| 21 |
from src.processing import page2image, image2base64
|
| 22 |
|
| 23 |
logger = logging.getLogger(__name__)
|
src/chains/pipelines.py
CHANGED
|
@@ -17,7 +17,7 @@ from src.chains.chains import (
|
|
| 17 |
VisionAnalysisChain
|
| 18 |
)
|
| 19 |
|
| 20 |
-
from src.config import Navigator
|
| 21 |
|
| 22 |
|
| 23 |
logger = logging.getLogger(__name__)
|
|
|
|
| 17 |
VisionAnalysisChain
|
| 18 |
)
|
| 19 |
|
| 20 |
+
from src.config.navigator import Navigator
|
| 21 |
|
| 22 |
|
| 23 |
logger = logging.getLogger(__name__)
|
src/config/navigator.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
from pathlib import Path
|
| 2 |
from dataclasses import dataclass
|
| 3 |
from typing import List, Optional, Union
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
@dataclass
|
| 6 |
class Navigator:
|
|
@@ -78,7 +81,7 @@ class Navigator:
|
|
| 78 |
if extension is not None:
|
| 79 |
results = [path for path in results if path.name.endswith(extension)]
|
| 80 |
if len(results) > 1:
|
| 81 |
-
|
| 82 |
|
| 83 |
if not results:
|
| 84 |
return None
|
|
|
|
| 1 |
from pathlib import Path
|
| 2 |
from dataclasses import dataclass
|
| 3 |
from typing import List, Optional, Union
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
logger = logging.getLogger(__name__)
|
| 7 |
|
| 8 |
@dataclass
|
| 9 |
class Navigator:
|
|
|
|
| 81 |
if extension is not None:
|
| 82 |
results = [path for path in results if path.name.endswith(extension)]
|
| 83 |
if len(results) > 1:
|
| 84 |
+
logger.info(f"Found {len(results)} matches for {substr}")
|
| 85 |
|
| 86 |
if not results:
|
| 87 |
return None
|
src/testing_utils/__init__.py
CHANGED
|
@@ -1,2 +1 @@
|
|
| 1 |
from src.testing_utils.echo_llm import EchoLLM
|
| 2 |
-
from src.testing_utils.display import query_and_display
|
|
|
|
| 1 |
from src.testing_utils.echo_llm import EchoLLM
|
|
|
src/testing_utils/display.py
DELETED
|
@@ -1,73 +0,0 @@
|
|
| 1 |
-
from typing import Optional, Union
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
import matplotlib.pyplot as plt
|
| 4 |
-
|
| 5 |
-
from src.config.multiline_wrapper import MultilineWrapper
|
| 6 |
-
from src.config import Navigator
|
| 7 |
-
from src.chains import SingleSlidePipeline
|
| 8 |
-
from langchain_core.language_models.base import BaseLanguageModel
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def query_and_display(
|
| 12 |
-
path: Union[str, Path],
|
| 13 |
-
page_num: int,
|
| 14 |
-
llm: BaseLanguageModel,
|
| 15 |
-
vision_prompt: Optional[str] = None,
|
| 16 |
-
wrap_width: Optional[int] = None,
|
| 17 |
-
display_image: bool = True
|
| 18 |
-
) -> dict:
|
| 19 |
-
"""Query vision model and display results
|
| 20 |
-
|
| 21 |
-
Args:
|
| 22 |
-
path: PDF file path or substring of filename
|
| 23 |
-
page_num: Zero-based page number
|
| 24 |
-
llm: Language model with vision capabilities
|
| 25 |
-
vision_prompt: Optional custom prompt to use
|
| 26 |
-
wrap_width: Width to wrap text output
|
| 27 |
-
display_image: Whether to display image with matplotlib
|
| 28 |
-
|
| 29 |
-
Returns:
|
| 30 |
-
Dictionary with model outputs
|
| 31 |
-
"""
|
| 32 |
-
# Find file if path is substring
|
| 33 |
-
nav = Navigator()
|
| 34 |
-
if isinstance(path, str):
|
| 35 |
-
pdf_path = nav.find_file_by_substr(path)
|
| 36 |
-
if pdf_path is None:
|
| 37 |
-
raise ValueError(f"No PDF found matching '{path}'")
|
| 38 |
-
else:
|
| 39 |
-
pdf_path = Path(path)
|
| 40 |
-
|
| 41 |
-
# Create slide processing pipeline
|
| 42 |
-
pipeline = SingleSlidePipeline(
|
| 43 |
-
llm=llm,
|
| 44 |
-
vision_prompt=vision_prompt if vision_prompt else "Describe this slide in detail"
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
# Process slide
|
| 48 |
-
result = pipeline.invoke({
|
| 49 |
-
"pdf_path": pdf_path,
|
| 50 |
-
"page_num": page_num
|
| 51 |
-
})
|
| 52 |
-
|
| 53 |
-
# Display results
|
| 54 |
-
if display_image:
|
| 55 |
-
fig, ax = plt.subplots(figsize=(12, 12))
|
| 56 |
-
# Convert page to image again to display
|
| 57 |
-
chain_result = (
|
| 58 |
-
pipeline._chain.invoke({
|
| 59 |
-
"pdf_path": pdf_path,
|
| 60 |
-
"page_num": page_num
|
| 61 |
-
})
|
| 62 |
-
)
|
| 63 |
-
ax.imshow(chain_result["image"])
|
| 64 |
-
ax.axis("off")
|
| 65 |
-
plt.show()
|
| 66 |
-
|
| 67 |
-
# Format and print text
|
| 68 |
-
text_wrapper = MultilineWrapper(width=wrap_width)
|
| 69 |
-
slide = result["slide_analysis"]
|
| 70 |
-
print(f"Prompt: {slide.vision_prompt}\n")
|
| 71 |
-
print(text_wrapper.fill(slide.content))
|
| 72 |
-
|
| 73 |
-
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|