Rushabh Dharmesh Gandhi commited on
Commit ·
537425f
1
Parent(s): 70ba0b9
fix: lint cleanup (unused imports, line length)
Browse files- routers/document.py +5 -1
- services/humanize_service.py +28 -17
- services/translate_service.py +0 -2
routers/document.py
CHANGED
|
@@ -27,7 +27,11 @@ class DocDownloadRequest(BaseModel):
|
|
| 27 |
filename: str
|
| 28 |
|
| 29 |
|
| 30 |
-
@router.post(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
async def upload_doc(
|
| 32 |
file: UploadFile = File(...),
|
| 33 |
mode: str = Form("humanize"),
|
|
|
|
| 27 |
filename: str
|
| 28 |
|
| 29 |
|
| 30 |
+
@router.post(
|
| 31 |
+
"/upload-doc",
|
| 32 |
+
response_model=DocProcessResponse,
|
| 33 |
+
summary="Upload a Word doc and humanize or paraphrase it",
|
| 34 |
+
)
|
| 35 |
async def upload_doc(
|
| 36 |
file: UploadFile = File(...),
|
| 37 |
mode: str = Form("humanize"),
|
services/humanize_service.py
CHANGED
|
@@ -12,8 +12,6 @@ from __future__ import annotations
|
|
| 12 |
import logging
|
| 13 |
import re
|
| 14 |
|
| 15 |
-
from config import settings
|
| 16 |
-
|
| 17 |
logger = logging.getLogger(__name__)
|
| 18 |
|
| 19 |
# Approximate character limit per chunk
|
|
@@ -64,21 +62,34 @@ def _split_into_chunks(text: str) -> list[str]:
|
|
| 64 |
return chunks if chunks else [text]
|
| 65 |
|
| 66 |
|
| 67 |
-
_SYSTEM_PROMPT =
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
def _humanize_llm(text: str) -> dict:
|
|
|
|
| 12 |
import logging
|
| 13 |
import re
|
| 14 |
|
|
|
|
|
|
|
| 15 |
logger = logging.getLogger(__name__)
|
| 16 |
|
| 17 |
# Approximate character limit per chunk
|
|
|
|
| 62 |
return chunks if chunks else [text]
|
| 63 |
|
| 64 |
|
| 65 |
+
_SYSTEM_PROMPT = ( # noqa: E501
|
| 66 |
+
"You are a skilled ghostwriter. Rewrite AI-generated text so it reads "
|
| 67 |
+
"as naturally human-written prose.\n\n"
|
| 68 |
+
"RULES:\n"
|
| 69 |
+
"1. Match the register and formality of the original. If the input is "
|
| 70 |
+
"academic, keep it academic but less robotic. If it's casual, stay casual.\n"
|
| 71 |
+
"2. Vary sentence length: mix short punchy sentences with longer flowing "
|
| 72 |
+
"ones. Never start 3+ consecutive sentences the same way.\n"
|
| 73 |
+
"3. Use everyday words and contractions (don't, it's, can't). Replace "
|
| 74 |
+
"AI-signature words: delve -> explore/dig into, utilize -> use, "
|
| 75 |
+
"facilitate -> help, commence -> start, comprehensive -> thorough, "
|
| 76 |
+
"leverage -> use, robust -> strong, cutting-edge -> latest.\n"
|
| 77 |
+
"4. Add subtle human touches: the occasional dash, an aside in "
|
| 78 |
+
"parentheses, a rhetorical question, or a transition like 'Thing is,' "
|
| 79 |
+
"or 'Now,' -- but don't overdo it.\n"
|
| 80 |
+
"5. Vary paragraph length. Some short (1-2 sentences), some longer.\n"
|
| 81 |
+
"6. Preserve ALL facts, arguments, and structure. Do NOT add new "
|
| 82 |
+
"information or meta-commentary.\n"
|
| 83 |
+
"7. Return ONLY the rewritten text. Keep roughly the same length "
|
| 84 |
+
"(within 15%).\n\n"
|
| 85 |
+
"EXAMPLE:\n"
|
| 86 |
+
'Input: "Artificial intelligence has commenced a comprehensive '
|
| 87 |
+
"transformation of the healthcare landscape, leveraging cutting-edge "
|
| 88 |
+
'algorithms to facilitate more robust diagnostic capabilities."\n'
|
| 89 |
+
'Output: "AI is reshaping healthcare in a big way. Modern algorithms '
|
| 90 |
+
"are making diagnostics sharper and more reliable -- and we're really "
|
| 91 |
+
'just getting started."'
|
| 92 |
+
)
|
| 93 |
|
| 94 |
|
| 95 |
def _humanize_llm(text: str) -> dict:
|
services/translate_service.py
CHANGED
|
@@ -5,8 +5,6 @@ Uses LLM (Groq / HF Inference) when available; falls back to Helsinki-NLP OpusMT
|
|
| 5 |
"""
|
| 6 |
from __future__ import annotations
|
| 7 |
|
| 8 |
-
from config import settings
|
| 9 |
-
|
| 10 |
# Map language codes to full names for better LLM prompts
|
| 11 |
LANG_NAMES: dict[str, str] = {
|
| 12 |
"af": "Afrikaans", "ar": "Arabic", "bg": "Bulgarian", "bn": "Bengali",
|
|
|
|
| 5 |
"""
|
| 6 |
from __future__ import annotations
|
| 7 |
|
|
|
|
|
|
|
| 8 |
# Map language codes to full names for better LLM prompts
|
| 9 |
LANG_NAMES: dict[str, str] = {
|
| 10 |
"af": "Afrikaans", "ar": "Arabic", "bg": "Bulgarian", "bn": "Bengali",
|