assitantchatbot / utils /docx_output_loader.py
aghaai's picture
Initial deployment of Unified Assistant with OpenAI and Hugging Face integration
bd161ec
raw
history blame contribute delete
729 Bytes
from docx import Document
import os
from typing import Optional
def extract_output_template_from_docx(docx_path: str) -> str:
"""Extracts the output template text from a .docx file (all paragraphs concatenated)."""
doc = Document(docx_path)
output = []
for para in doc.paragraphs:
text = para.text.strip()
if text:
output.append(text)
return '\n'.join(output)
def find_output_docx_file_in_folder(folder_path: str) -> Optional[str]:
"""Finds the first .docx file in a folder and returns its path, or None if not found."""
for fname in os.listdir(folder_path):
if fname.lower().endswith('.docx'):
return os.path.join(folder_path, fname)
return None