Spaces:
Build error
Build error
| """ | |
| ⚖️ Title: 🤖 eRAG-PDPA | |
| License: Apache-2.0 | |
| This project is licensed under the Apache License, Version 2.0 (the "License"); | |
| you may not use this file except in compliance with the License. | |
| You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software | |
| distributed under the License is distributed on an "AS IS" BASIS, | |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| See the License for the specific language governing permissions and | |
| limitations under the License. | |
| For inquiries or contributions, please contact: | |
| amornpan@gmail.com | |
| """ | |
| import streamlit as st | |
| import requests | |
| import os | |
| st.title('eRAG-PDPA-v1') | |
| st.markdown(""" | |
| ##### 🤖 AI เพื่อการเรียนรู้พระราชบัญญัติคุ้มครองข้อมูลส่วนบุคคล (PDPA) | |
| ได้รับการออกแบบมาเพื่อช่วยให้ผู้ใช้งานเข้าถึงข้อมูลสำคัญได้อย่างรวดเร็วและเข้าใจง่าย | |
| โดยระบบสามารถค้นหาและวิเคราะห์ความหมายในเชิงบริบทได้อย่างลึกซึ้ง | |
| ทำให้สามารถเข้าใจความเชื่อมโยงและความหมายของข้อมูลได้อย่างแม่นยำ | |
| รองรับการเรียนรู้เชิงลึกในประเด็นเกี่ยวกับ PDPA และการคุ้มครองข้อมูลส่วนบุคคลได้อย่างมีประสิทธิภาพ | |
| [Powered by NT Lahnmah] | |
| """, unsafe_allow_html=True) | |
| def format_file_size(size_in_bytes): | |
| for unit in ['B', 'KB', 'MB', 'GB']: | |
| if size_in_bytes < 1024: | |
| return f"{size_in_bytes:.2f} {unit}" | |
| size_in_bytes /= 1024 | |
| return f"{size_in_bytes:.2f} GB" | |
| def display_search_result(result, index): | |
| with st.expander(f"🔍 Search Result #{index + 1} (Score: {result['score']:.4f})"): | |
| st.markdown("#### 📄 Document Information") | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.write(f"• File Name: {result['metadata']['file_name']}") | |
| st.write(f"• Page: {result['metadata']['page_label']}") | |
| st.write(f"• Type: {result['metadata']['file_type']}") | |
| st.write(f"• Size: {format_file_size(result['metadata']['file_size'])}") | |
| with col2: | |
| st.write(f"• Created: {result['metadata']['creation_date']}") | |
| st.write(f"• Modified: {result['metadata']['last_modified_date']}") | |
| st.markdown("#### 📝 Content") | |
| st.markdown(f"<div style='background-color:#d3f9d8; padding: 10px; color: black;'><pre>{result['text']}</pre></div>", unsafe_allow_html=True) | |
| access_token = os.getenv('eRAG_access_token') | |
| headers = { | |
| "Authorization": f"Bearer {access_token}" | |
| } | |
| st.markdown(""" | |
| <style> | |
| .stTextInput>div>div>input { | |
| background-color: #d3f9d8; | |
| color: black; | |
| cursor: text; | |
| caret-color: black; | |
| } | |
| .stTextInput>div>div>input:focus { | |
| border-color: black; | |
| outline-color: black; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| api_url = os.getenv('api_url') | |
| with st.form(key="input_form"): | |
| user_input = st.text_input("ป้อนคำ ข้อความ หรือประโยคที่ต้องการค้นหา:", value="ข้อมูลส่วนบุคคล คืออะไร มีกี่ประเภท", key="input") | |
| submit_button = st.form_submit_button("Send") | |
| if submit_button and user_input: | |
| st.write(f"คุณป้อนข้อความ: {user_input}") | |
| try: | |
| response = requests.post(api_url, json={"query": user_input}, headers=headers) | |
| response.raise_for_status() | |
| data = response.json() | |
| search_results = data["results"] | |
| st.markdown("### 🔎 Search Results") | |
| for idx, result in enumerate(search_results): | |
| display_search_result(result, idx) | |
| except requests.RequestException as e: | |
| st.error(f"Error: {str(e)}") | |
| st.subheader("📄 ไฟล์เอกสารที่ใช้เป็นคลังข้อมูล PDPA") | |
| st.markdown( | |
| """ | |
| - [FAQ-เกี่ยวกับการคุ้มครองข้อมูลส่วนบุคคล-PDPA.pdf](https://huggingface.co/spaces/amornpan/eRAG-PDPA-v1/blob/main/%E0%B9%80%E0%B8%AD%E0%B8%81%E0%B8%AA%E0%B8%B2%E0%B8%A3_PDPA/1.FAQ-%E0%B9%80%E0%B8%81%E0%B8%B5%E0%B9%88%E0%B8%A2%E0%B8%A7%E0%B8%81%E0%B8%B1%E0%B8%9A%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%84%E0%B8%B8%E0%B9%89%E0%B8%A1%E0%B8%84%E0%B8%A3%E0%B8%AD%E0%B8%87%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%A1%E0%B8%B9%E0%B8%A5%E0%B8%AA%E0%B9%88%E0%B8%A7%E0%B8%99%E0%B8%9A%E0%B8%B8%E0%B8%84%E0%B8%84%E0%B8%A5-PDPA.pdf) (1.13 MB) | |
| - [1612025563SummaryPDPA_DigitalCouncilofThailand.pdf](https://huggingface.co/spaces/amornpan/eRAG-PDPA-v1/blob/main/%E0%B9%80%E0%B8%AD%E0%B8%81%E0%B8%AA%E0%B8%B2%E0%B8%A3_PDPA/1612025563SummaryPDPA_DigitalCouncilofThailand.pdf) (1.35 MB) | |
| - [PDPA_Guideline_v_1.pdf](https://huggingface.co/spaces/amornpan/eRAG-PDPA-v1/blob/main/%E0%B9%80%E0%B8%AD%E0%B8%81%E0%B8%AA%E0%B8%B2%E0%B8%A3_PDPA/PDPA_Guideline_v_1.pdf) (10.7 MB) | |
| - [T_0024.pdf](https://huggingface.co/spaces/amornpan/eRAG-PDPA-v1/blob/main/%E0%B9%80%E0%B8%AD%E0%B8%81%E0%B8%AA%E0%B8%B2%E0%B8%A3_PDPA/T_0024.pdf) (81.1 kB) | |
| - [T_0026.pdf](https://huggingface.co/spaces/amornpan/eRAG-PDPA-v1/blob/main/%E0%B9%80%E0%B8%AD%E0%B8%81%E0%B8%AA%E0%B8%B2%E0%B8%A3_PDPA/T_0026.pdf) (82.6 kB) | |
| - [T_0028.pdf](https://huggingface.co/spaces/amornpan/eRAG-PDPA-v1/blob/main/%E0%B9%80%E0%B8%AD%E0%B8%81%E0%B8%AA%E0%B8%B2%E0%B8%A3_PDPA/T_0028.pdf) (105 kB) | |
| - [T_0032.pdf](https://huggingface.co/spaces/amornpan/eRAG-PDPA-v1/blob/main/%E0%B9%80%E0%B8%AD%E0%B8%81%E0%B8%AA%E0%B8%B2%E0%B8%A3_PDPA/T_0032.pdf) (103 kB) | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| st.subheader("👤 Authors") | |
| st.write(""" | |
| - Amornpan Phornchaicharoen (amornpan@gmail.com) | |
| - Aekanun Thongtae (cto@bangkokfirsttech.com) | |
| - Montita Somsoo (montita.fonn@gmail.com) | |
| """) |