procurement-tools/auto-form
Auto Form Generator
ระบบสร้างหนังสือราชการอัตโนมัติจากแบบฟอร์มมาตรฐาน 5 ประเภท พร้อมดึงข้อมูล PO อัตโนมัติจากไฟล์ Excel
 
✨ Features
- 📄 รองรับ 5 แบบฟอร์มมาตรฐาน
- 🔍 Auto-fill จาก Excel — ใส่ PO แล้วระบบเติม Vendor, ชื่องาน ฯลฯ ให้อัตโนมัติ
- ✏️ รักษารูปแบบเอกสารต้นฉบับ (Font, สี, layout)
- 🌐 รันบนเว็บได้เลย ไม่ต้องติดตั้งอะไร
- 🚀 ทำงานบน Hugging Face Spaces ฟรี
📦 Tech Stack
- Python 3.11 + Streamlit (web UI)
- python-docx (สร้างเอกสาร Word)
- openpyxl (อ่านไฟล์ Excel)
- Docker (deployment on Hugging Face Spaces)
🚀 Run Locally
pip install -r requirements.txt
streamlit run streamlit_app.pyเปิดเบราว์เซอร์ที่ http://localhost:8501
🔐 Authentication (Microsoft Entra ID)
The app is gated behind Microsoft sign-in using Streamlit's native OIDC auth (st.login). It reuses an existing Azure App Registration.
Local: copy .streamlit/secrets.toml.template to .streamlit/secrets.toml and fill in the values (this file is gitignored). Register http://localhost:8501/oauth2callback as a Web redirect URI in Azure.
Hugging Face Spaces: secrets.toml is built at startup by entrypoint.sh from these Space secrets — set them in Settings → Variables and secrets:
🔏 Signer auto-fill (ผู้มีอำนาจอนุมัติ / ประธานกรรมการตรวจรับ)
The two signer names ride the same OneDrive `DATA_URL` file the app already reads — the app never calls the PTT gateway itself. It can't: the gateway is a private 10.x host, and a public webpage is blocked from it by Chrome's Private Network Access (so neither a browser nor the HF server can fetch it). Instead, the Power BI model fetches the names during its scheduled refresh, which runs through an On-premises Data Gateway (personal mode) on a PTT-connected PC where the gateway is reachable. The model adds two columns — `approverName` and `chairmanName` — and the app reads them per PO (signer_lookup.SIGNER_COLUMN); if a column is blank it offers a manual ชื่อผู้ลงนาม box.
- Model-side query + full setup steps live in `powerquery_signers.pq` (create the
SMPTokenparameter = the no-reply bearer, bind the dataset to your personal gateway, schedule refresh). - Nothing is needed on the Space for this: no
SMP_TOKENsecret, nostreamlit-javascript.
Register the same https://<space-host>/oauth2callback as a Web redirect URI in Azure. Sign-in stays broken until both the Space secrets and the Azure redirect URI are in place.
📋 Project Structure
.
├── Dockerfile # HF Spaces container config
├── README.md # This file (with HF YAML frontmatter)
├── requirements.txt # Python dependencies
├── streamlit_app.py # Web UI (main entry point)
├── form_logic.py # Document generation logic
├── excel_lookup.py # Excel data lookup helper (legacy, unused by web app)
├── sample_po_data.xlsx # Sample data for demo
├── .streamlit/
│ └── config.toml # Theme & toolbar config
└── templates/
└── form1-5.docx # Word templates📄 License
MIT
