Spaces:
Build error
Build error
prashant commited on
Commit ·
ecb69bb
1
Parent(s): 9f53222
Initial commit
Browse files- .env +3 -0
- README.md +36 -7
- app.py +112 -0
- assets/style.css +4 -0
- core/agents.py +51 -0
- core/config.py +15 -0
- core/prompts.py +26 -0
- core/report_builder.py +40 -0
- core/schema.py +14 -0
- examples/sample_input.txt +1 -0
- packages.txt +2 -0
- requirements.txt +7 -0
- tools/image_parser.py +6 -0
- tools/notebook_tool.py +2 -0
- tools/pdf_parser.py +13 -0
- tools/text_cleaner.py +7 -0
- utils/file_utils.py +19 -0
- utils/logging_utils.py +16 -0
- utils/validators.py +8 -0
.env
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
APP_NAME="prashantpatil3299/ProjectLensAI"
|
| 2 |
+
APP_ENV=production
|
| 3 |
+
MAX_TEXT_LENGTH=5000
|
README.md
CHANGED
|
@@ -1,14 +1,43 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 6.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
short_description: A
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: UniversalProjectSpace
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.6.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: A reusable Hugging Face Space template for AI, NLP, CV, PDF, and interview projects.
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Universal Project Space
|
| 15 |
+
|
| 16 |
+
This Hugging Face Space is a reusable starter template for any kind of project.
|
| 17 |
+
|
| 18 |
+
## Features
|
| 19 |
+
- Text input
|
| 20 |
+
- File upload
|
| 21 |
+
- Optional image handling
|
| 22 |
+
- Report generation
|
| 23 |
+
- Modular Python structure
|
| 24 |
+
|
| 25 |
+
## How to use
|
| 26 |
+
1. Enter your project text
|
| 27 |
+
2. Upload optional files
|
| 28 |
+
3. Click **Run Analysis**
|
| 29 |
+
4. Download or copy the generated result
|
| 30 |
+
|
| 31 |
+
## Replaceable Modules
|
| 32 |
+
- `core/agents.py` → main business logic
|
| 33 |
+
- `parsers/` → parse PDF/image/text
|
| 34 |
+
- `core/report_builder.py` → format final output
|
| 35 |
+
- `app.py` → UI
|
| 36 |
+
|
| 37 |
+
## Example Use Cases
|
| 38 |
+
- Interview project explainer
|
| 39 |
+
- Resume analyzer
|
| 40 |
+
- PDF summarizer
|
| 41 |
+
- Insurance cross-sell prediction explainer
|
| 42 |
+
- Recommendation system demo
|
| 43 |
+
- Image/text/document understanding
|
app.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import tempfile
|
| 3 |
+
from typing import Optional
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
+
from core.agents import ProjectAgent
|
| 9 |
+
from core.config import settings
|
| 10 |
+
from utils.logging_utils import get_logger
|
| 11 |
+
from utils.file_utils import save_uploaded_file
|
| 12 |
+
|
| 13 |
+
load_dotenv()
|
| 14 |
+
|
| 15 |
+
logger = get_logger(__name__)
|
| 16 |
+
agent = ProjectAgent()
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def run_project(
|
| 20 |
+
project_type: str,
|
| 21 |
+
user_text: str,
|
| 22 |
+
uploaded_file: Optional[str],
|
| 23 |
+
tone: str
|
| 24 |
+
):
|
| 25 |
+
try:
|
| 26 |
+
saved_path = None
|
| 27 |
+
|
| 28 |
+
if uploaded_file:
|
| 29 |
+
saved_path = save_uploaded_file(uploaded_file)
|
| 30 |
+
|
| 31 |
+
result = agent.process(
|
| 32 |
+
project_type=project_type,
|
| 33 |
+
user_text=user_text,
|
| 34 |
+
file_path=saved_path,
|
| 35 |
+
tone=tone
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
return result["summary"], result["report"]
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
logger.exception("Error while processing project")
|
| 42 |
+
return f"Error: {str(e)}", f"Detailed error:\n{str(e)}"
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
with gr.Blocks(title=settings.APP_NAME, theme=gr.themes.Soft()) as demo:
|
| 46 |
+
gr.Markdown(
|
| 47 |
+
f"""
|
| 48 |
+
# {settings.APP_NAME}
|
| 49 |
+
A reusable Hugging Face Space template for **any kind of project**.
|
| 50 |
+
|
| 51 |
+
### Supported ideas
|
| 52 |
+
- Data science project explainer
|
| 53 |
+
- Interview answer generator
|
| 54 |
+
- Resume/project summary
|
| 55 |
+
- PDF/image/text analysis
|
| 56 |
+
- Recommendation/prediction demo
|
| 57 |
+
"""
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
with gr.Row():
|
| 61 |
+
with gr.Column():
|
| 62 |
+
project_type = gr.Dropdown(
|
| 63 |
+
choices=[
|
| 64 |
+
"Data Science Project",
|
| 65 |
+
"Interview Project Explanation",
|
| 66 |
+
"Resume Project Summary",
|
| 67 |
+
"PDF Summary",
|
| 68 |
+
"Image Analysis",
|
| 69 |
+
"Custom Project"
|
| 70 |
+
],
|
| 71 |
+
value="Interview Project Explanation",
|
| 72 |
+
label="Project Type"
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
user_text = gr.Textbox(
|
| 76 |
+
label="Enter your project/problem statement",
|
| 77 |
+
placeholder="Example: Explain my insurance cross-sell prediction and recommendation project for interview...",
|
| 78 |
+
lines=10,
|
| 79 |
+
max_lines=20
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
uploaded_file = gr.File(
|
| 83 |
+
label="Upload optional file (pdf/txt/image)",
|
| 84 |
+
type="filepath"
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
tone = gr.Radio(
|
| 88 |
+
choices=["Professional", "Simple", "Technical", "Interview-ready"],
|
| 89 |
+
value="Interview-ready",
|
| 90 |
+
label="Tone"
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
run_btn = gr.Button("Run Analysis", variant="primary")
|
| 94 |
+
|
| 95 |
+
with gr.Column():
|
| 96 |
+
summary_output = gr.Textbox(
|
| 97 |
+
label="Summary",
|
| 98 |
+
lines=12
|
| 99 |
+
)
|
| 100 |
+
report_output = gr.Textbox(
|
| 101 |
+
label="Detailed Report",
|
| 102 |
+
lines=20
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
run_btn.click(
|
| 106 |
+
fn=run_project,
|
| 107 |
+
inputs=[project_type, user_text, uploaded_file, tone],
|
| 108 |
+
outputs=[summary_output, report_output]
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
if __name__ == "__main__":
|
| 112 |
+
demo.launch()
|
assets/style.css
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.gradio-container {
|
| 2 |
+
max-width: 1200px !important;
|
| 3 |
+
margin: auto !important;
|
| 4 |
+
}
|
core/agents.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from typing import Optional
|
| 3 |
+
|
| 4 |
+
from core.schema import ProjectRequest, ProjectResponse
|
| 5 |
+
from core.report_builder import build_report
|
| 6 |
+
from parsers.pdf_parser import extract_text_from_pdf
|
| 7 |
+
from parsers.image_parser import describe_image_file
|
| 8 |
+
from parsers.text_cleaner import clean_text
|
| 9 |
+
from utils.file_utils import read_text_file
|
| 10 |
+
from utils.logging_utils import get_logger
|
| 11 |
+
|
| 12 |
+
logger = get_logger(__name__)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class ProjectAgent:
|
| 16 |
+
def process(
|
| 17 |
+
self,
|
| 18 |
+
project_type: str,
|
| 19 |
+
user_text: str,
|
| 20 |
+
file_path: Optional[str] = None,
|
| 21 |
+
tone: str = "Professional"
|
| 22 |
+
):
|
| 23 |
+
extracted_text = user_text.strip()
|
| 24 |
+
|
| 25 |
+
if file_path:
|
| 26 |
+
ext = os.path.splitext(file_path)[1].lower()
|
| 27 |
+
|
| 28 |
+
if ext == ".pdf":
|
| 29 |
+
pdf_text = extract_text_from_pdf(file_path)
|
| 30 |
+
extracted_text += f"\n\n[PDF CONTENT]\n{pdf_text}"
|
| 31 |
+
|
| 32 |
+
elif ext in [".png", ".jpg", ".jpeg", ".webp"]:
|
| 33 |
+
image_desc = describe_image_file(file_path)
|
| 34 |
+
extracted_text += f"\n\n[IMAGE DESCRIPTION]\n{image_desc}"
|
| 35 |
+
|
| 36 |
+
elif ext in [".txt", ".md", ".csv"]:
|
| 37 |
+
file_text = read_text_file(file_path)
|
| 38 |
+
extracted_text += f"\n\n[FILE CONTENT]\n{file_text}"
|
| 39 |
+
|
| 40 |
+
else:
|
| 41 |
+
extracted_text += f"\n\n[NOTE] Uploaded file type not fully supported yet: {ext}"
|
| 42 |
+
|
| 43 |
+
extracted_text = clean_text(extracted_text)
|
| 44 |
+
|
| 45 |
+
result = build_report(
|
| 46 |
+
project_type=project_type,
|
| 47 |
+
tone=tone,
|
| 48 |
+
extracted_text=extracted_text
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
return result
|
core/config.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dataclasses import dataclass
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
|
| 5 |
+
load_dotenv()
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@dataclass
|
| 9 |
+
class Settings:
|
| 10 |
+
APP_NAME: str = os.getenv("APP_NAME", "Universal Project Space")
|
| 11 |
+
APP_ENV: str = os.getenv("APP_ENV", "development")
|
| 12 |
+
MAX_TEXT_LENGTH: int = int(os.getenv("MAX_TEXT_LENGTH", "5000"))
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
settings = Settings()
|
core/prompts.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BASE_PROMPT = """
|
| 2 |
+
You are an expert project explainer.
|
| 3 |
+
Your task is to explain user projects clearly and professionally.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
INTERVIEW_PROMPT = """
|
| 7 |
+
Explain the project in an interview-ready way.
|
| 8 |
+
Cover:
|
| 9 |
+
1. Problem statement
|
| 10 |
+
2. Business objective
|
| 11 |
+
3. Data used
|
| 12 |
+
4. Feature engineering
|
| 13 |
+
5. Model selection
|
| 14 |
+
6. Evaluation metrics
|
| 15 |
+
7. Business impact
|
| 16 |
+
8. Future improvements
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
TECHNICAL_PROMPT = """
|
| 20 |
+
Explain the project in a technical way.
|
| 21 |
+
Include architecture, workflow, preprocessing, algorithms, and deployment ideas.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
SIMPLE_PROMPT = """
|
| 25 |
+
Explain the project in simple human-friendly language for beginners.
|
| 26 |
+
"""
|
core/report_builder.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def build_report(project_type: str, tone: str, extracted_text: str) -> Dict[str, str]:
|
| 5 |
+
summary = (
|
| 6 |
+
f"Project Type: {project_type}\n"
|
| 7 |
+
f"Tone: {tone}\n"
|
| 8 |
+
f"Overview: {extracted_text[:400]}..."
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
report = f"""
|
| 12 |
+
PROJECT REPORT
|
| 13 |
+
==============
|
| 14 |
+
|
| 15 |
+
Project Type:
|
| 16 |
+
{project_type}
|
| 17 |
+
|
| 18 |
+
Preferred Tone:
|
| 19 |
+
{tone}
|
| 20 |
+
|
| 21 |
+
Detailed Explanation:
|
| 22 |
+
{extracted_text}
|
| 23 |
+
|
| 24 |
+
Suggested Interview Flow:
|
| 25 |
+
1. Start with the business problem.
|
| 26 |
+
2. Explain the data source and preprocessing.
|
| 27 |
+
3. Mention model/logic used.
|
| 28 |
+
4. Show evaluation or result.
|
| 29 |
+
5. Explain business value.
|
| 30 |
+
6. End with future improvements.
|
| 31 |
+
|
| 32 |
+
Sample Closing:
|
| 33 |
+
"This project helped solve a real business problem by combining data preprocessing,
|
| 34 |
+
predictive modeling, and actionable recommendations."
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
return {
|
| 38 |
+
"summary": summary.strip(),
|
| 39 |
+
"report": report.strip()
|
| 40 |
+
}
|
core/schema.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
from typing import Optional
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class ProjectRequest(BaseModel):
|
| 6 |
+
project_type: str
|
| 7 |
+
user_text: str
|
| 8 |
+
file_path: Optional[str] = None
|
| 9 |
+
tone: str = "Professional"
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class ProjectResponse(BaseModel):
|
| 13 |
+
summary: str
|
| 14 |
+
report: str
|
examples/sample_input.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
I built an insurance cross-sell prediction project where the goal was to predict which existing health insurance customers are likely to buy vehicle insurance. I used customer demographic and policy-related features, performed preprocessing, trained classification models, evaluated them using ROC-AUC and F1-score, and then created recommendations for high-probability customers.
|
packages.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
poppler-utils
|
| 2 |
+
tesseract-ocr
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==5.6.0
|
| 2 |
+
python-dotenv==1.0.1
|
| 3 |
+
pydantic==2.9.2
|
| 4 |
+
pillow==10.4.0
|
| 5 |
+
pandas==2.2.2
|
| 6 |
+
numpy==2.1.1
|
| 7 |
+
PyPDF2==3.0.1
|
tools/image_parser.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def describe_image_file(file_path: str) -> str:
|
| 5 |
+
filename = os.path.basename(file_path)
|
| 6 |
+
return f"Image uploaded successfully: {filename}. Add your vision model logic here."
|
tools/notebook_tool.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inspect_notebook(file_path: str) -> str:
|
| 2 |
+
return f"Notebook support placeholder for file: {file_path}"
|
tools/pdf_parser.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PyPDF2 import PdfReader
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def extract_text_from_pdf(file_path: str) -> str:
|
| 5 |
+
text_chunks = []
|
| 6 |
+
try:
|
| 7 |
+
reader = PdfReader(file_path)
|
| 8 |
+
for page in reader.pages:
|
| 9 |
+
page_text = page.extract_text() or ""
|
| 10 |
+
text_chunks.append(page_text)
|
| 11 |
+
return "\n".join(text_chunks).strip()
|
| 12 |
+
except Exception as e:
|
| 13 |
+
return f"Could not parse PDF: {str(e)}"
|
tools/text_cleaner.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def clean_text(text: str) -> str:
|
| 5 |
+
text = re.sub(r"\n{3,}", "\n\n", text)
|
| 6 |
+
text = re.sub(r"[ \t]+", " ", text)
|
| 7 |
+
return text.strip()
|
utils/file_utils.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import tempfile
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def save_uploaded_file(uploaded_path: str) -> str:
|
| 7 |
+
temp_dir = tempfile.mkdtemp()
|
| 8 |
+
filename = os.path.basename(uploaded_path)
|
| 9 |
+
new_path = os.path.join(temp_dir, filename)
|
| 10 |
+
shutil.copy(uploaded_path, new_path)
|
| 11 |
+
return new_path
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def read_text_file(file_path: str) -> str:
|
| 15 |
+
try:
|
| 16 |
+
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
| 17 |
+
return f.read()
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"Could not read text file: {str(e)}"
|
utils/logging_utils.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def get_logger(name: str) -> logging.Logger:
|
| 5 |
+
logger = logging.getLogger(name)
|
| 6 |
+
|
| 7 |
+
if not logger.handlers:
|
| 8 |
+
logger.setLevel(logging.INFO)
|
| 9 |
+
handler = logging.StreamHandler()
|
| 10 |
+
formatter = logging.Formatter(
|
| 11 |
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
| 12 |
+
)
|
| 13 |
+
handler.setFormatter(formatter)
|
| 14 |
+
logger.addHandler(handler)
|
| 15 |
+
|
| 16 |
+
return logger
|
utils/validators.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def validate_input_text(text: str, max_length: int = 5000):
|
| 2 |
+
if not text or not text.strip():
|
| 3 |
+
raise ValueError("Input text cannot be empty.")
|
| 4 |
+
|
| 5 |
+
if len(text) > max_length:
|
| 6 |
+
raise ValueError(f"Input text exceeds max length of {max_length} characters.")
|
| 7 |
+
|
| 8 |
+
return True
|