Spaces:
Build error
Build error
Download core/agents.py from prashantpatil3299/ProjectLensAI: direct link, hf CLI and curl.
- Browser
- Download file 1.58 kB
-
https://huggingface.co/spaces/prashantpatil3299/ProjectLensAI/resolve/main/core/agents.py
- Command line
-
hf download hf://spaces/prashantpatil3299/ProjectLensAI/core/agents.py
-
curl -L -o agents.py https://huggingface.co/spaces/prashantpatil3299/ProjectLensAI/resolve/main/core/agents.py
1.58 kB
| import os | |
| from typing import Optional | |
| from core.schema import ProjectRequest, ProjectResponse | |
| from core.report_builder import build_report | |
| from parsers.pdf_parser import extract_text_from_pdf | |
| from parsers.image_parser import describe_image_file | |
| from parsers.text_cleaner import clean_text | |
| from utils.file_utils import read_text_file | |
| from utils.logging_utils import get_logger | |
| logger = get_logger(__name__) | |
| class ProjectAgent: | |
| def process( | |
| self, | |
| project_type: str, | |
| user_text: str, | |
| file_path: Optional[str] = None, | |
| tone: str = "Professional" | |
| ): | |
| extracted_text = user_text.strip() | |
| if file_path: | |
| ext = os.path.splitext(file_path)[1].lower() | |
| if ext == ".pdf": | |
| pdf_text = extract_text_from_pdf(file_path) | |
| extracted_text += f"\n\n[PDF CONTENT]\n{pdf_text}" | |
| elif ext in [".png", ".jpg", ".jpeg", ".webp"]: | |
| image_desc = describe_image_file(file_path) | |
| extracted_text += f"\n\n[IMAGE DESCRIPTION]\n{image_desc}" | |
| elif ext in [".txt", ".md", ".csv"]: | |
| file_text = read_text_file(file_path) | |
| extracted_text += f"\n\n[FILE CONTENT]\n{file_text}" | |
| else: | |
| extracted_text += f"\n\n[NOTE] Uploaded file type not fully supported yet: {ext}" | |
| extracted_text = clean_text(extracted_text) | |
| result = build_report( | |
| project_type=project_type, | |
| tone=tone, | |
| extracted_text=extracted_text | |
| ) | |
| return result |