Spaces:
Sleeping
Sleeping
|
Download README.md from procurement-tools/auto-form: direct link, hf CLI and curl.
- Browser
- Download file 4.63 kB
-
https://huggingface.co/spaces/procurement-tools/auto-form/resolve/main/README.md
- Command line
-
hf download hf://spaces/procurement-tools/auto-form/README.md
-
curl -L -o README.md https://huggingface.co/spaces/procurement-tools/auto-form/resolve/main/README.md
4.63 kB
| title: Auto Form Generator | |
| emoji: 📄 | |
| colorFrom: blue | |
| colorTo: indigo | |
| sdk: docker | |
| app_port: 7860 | |
| pinned: false | |
| short_description: Auto-generate procurement letters from Excel data | |
| # Auto Form Generator | |
| ระบบสร้างหนังสือราชการอัตโนมัติจากแบบฟอร์มมาตรฐาน 5 ประเภท พร้อมดึงข้อมูล PO อัตโนมัติจากไฟล์ Excel | |
| [](https://www.python.org/) | |
| [](LICENSE) | |
| --- | |
| ## ✨ 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 | |
| ```bash | |
| 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*: | |
| | Secret | Value | | |
| | --- | --- | | |
| | `AUTH_CLIENT_ID` | Azure app (client) id | | |
| | `AUTH_CLIENT_SECRET` | Azure client secret | | |
| | `AUTH_COOKIE_SECRET` | any long random hex string | | |
| | `AUTH_REDIRECT_URI` | `https://<space-host>/oauth2callback` | | |
| | `AUTH_SERVER_METADATA_URL` | `https://login.microsoftonline.com/<tenant>/v2.0/.well-known/openid-configuration` | | |
| | `DATA_URL` | OneDrive "anyone with the link" URL of the PO-data Excel (Power BI export) | | |
| ## 🔏 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 `SMPToken` | |
| parameter = the no-reply bearer, bind the dataset to your personal gateway, schedule refresh). | |
| - Nothing is needed on the Space for this: no `SMP_TOKEN` secret, no `streamlit-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 | |