Spaces:
Running
Running
""" | |
⚖️ Title: 🤖 eRAG-Election | |
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: | |
[email protected] | |
""" | |
import streamlit as st | |
import requests | |
import os | |
st.title('Local eRAG-Elections v1') | |
st.markdown(""" | |
##### 🤖 AI เพื่อการปรับปรุงงาน กกต. | |
ระบบ AI นี้ถูกออกแบบมาเพื่อช่วยให้คณะกรรมการการเลือกตั้ง (กกต.) เข้าถึงข้อมูลและการวิเคราะห์ความหมายในเชิงบริบทได้อย่างลึกซึ้ง | |
ทำให้สามารถเข้าใจความเชื่อมโยงและความหมายของข้อมูลในสถานการณ์การเลือกตั้งได้อย่างแม่นยำ | |
ระบบได้รับการออกแบบเพื่อรองรับการเรียนรู้เชิงลึกและการประมวลผลข้อมูลเกี่ยวกับการเลือกตั้งและการจัดการข้อมูลผู้มีสิทธิเลือกตั้ง | |
**ประโยชน์ที่ได้รับ:** | |
1. **ลดการตอบนอกเรื่องและความผิดพลาด (No hallucinate)**: ช่วยให้กระบวนการต่างๆ ในองค์กรมีความชัดเจนและถูกต้องมากขึ้น โดยปรับปรุงและควบคุมคุณภาพของข้อมูลและการสื่อสารภายในองค์กร เพื่อลดความผิดพลาดและการตอบรับที่ไม่ตรงกับประเด็นที่ถูกต้อง | |
2. **ประหยัดต้นทุนและเพิ่มประสิทธิภาพการใช้ทรัพยากร (No API cost)**: ช่วยลดการสูญเสียรายได้จากข้อผิดพลาดในการบริหารจัดการข้อมูลและกระบวนการ ตลอดจนเพิ่มความเสียงในการจัดสรรทรัพยากรที่มีอยู่ให้เกิดประโยชน์สูงสุด | |
3. **เพิ่มความมั่นคงและความปลอดภัยของข้อมูล (No data leakage)**: ดำเนินการป้องกันและตรวจสอบการรั่วไหลของข้อมูล เพื่อปกป้องข้อมูลสำคัญจากการเข้าถึงโดยไม่ได้รับอนุญาต ซึ่งช่วยเพิ่มความไว้วางใจในองค์กร | |
4. **เพิ่มความรวดเร็วในการประมวลผลข้อมูล (Increase speed)**: AI สามารถวิเคราะห์ข้อมูลจำนวนมหาศาลได้อย่างรวดเร็ว ช่วยให้การจัดเก็บและการวิเคราะห์ข้อมูลเป็นไปอย่างมีประสิทธิภาพและถูกต้อง | |
5. **การตัดสินใจที่มีข้อมูลเชิงลึก (Decision-making)**: การใช้ AI ในการวิเคราะห์และตีความข้อมูลช่วยให้ผู้กำหนดนโยบายสามารถตัดสินใจที่ดีขึ้นด้วยข้อมูลที่เข้าใจง่ายและแม่นยำ | |
6. **การปรับปรุงความโปร่งใสและความเป็นธรรมในการเลือกตั้ง (Improve transparency and fairness in elections)**: ด้วยการวิเคราะห์ข้อมูลที่ละเอียดและการตรวจจับปัญหาที่อาจเกิดขึ้นได้รับการแก้ไขอย่างทันท่วงที | |
7. **ความแม่นยำในการจัดการข้อมูลผู้มีสิทธิเลือกตั้ง (Accuracy in voter data management)**: AI ช่วยให้สามารถจัดการและปรับปรุงคุณภาพข้อมูลผู้มีสิทธิเลือกตั้ง เพื่อให้การสร้างสารบบเลือกตั้งที่เป็นธรรมและเที่ยงตรง | |
""", 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("📄 ไฟล์เอกสารที่ใช้เป็นคลังข้อมูล eRAG-Election") | |
st.markdown( | |
""" | |
- [พระราชบัญญัติการเลือกตั้งสมาชิกสภาท้องถิ่นหรือผู้บริหารท้องถิ่น พ.ศ. 2562.pdf](https://huggingface.co/spaces/amornpan/eRAG-Election/blob/main/%E0%B8%9E%E0%B8%A3%E0%B8%B0%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%9A%E0%B8%B1%E0%B8%8D%E0%B8%8D%E0%B8%B1%E0%B8%95%E0%B8%B4%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%A5%E0%B8%B7%E0%B8%AD%E0%B8%81%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87%E0%B8%AA%E0%B8%A1%E0%B8%B2%E0%B8%8A%E0%B8%B4%E0%B8%81%E0%B8%AA%E0%B8%A0%E0%B8%B2%E0%B8%97%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%96%E0%B8%B4%E0%B9%88%E0%B8%99%E0%B8%AB%E0%B8%A3%E0%B8%B7%E0%B8%AD%E0%B8%9C%E0%B8%B9%E0%B9%89%E0%B8%9A%E0%B8%A3%E0%B8%B4%E0%B8%AB%E0%B8%B2%E0%B8%A3%E0%B8%97%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%96%E0%B8%B4%E0%B9%88%E0%B8%99%20%E0%B8%9E.%E0%B8%A8.%202562.pdf) (378 kB) | |
""", | |
unsafe_allow_html=True | |
) | |