PRISM / app.py
nguyenthanhasia's picture
Upload 116 files
9aad4d7 verified
Raw
History Blame Contribute Delete
2.33 kB
#!/usr/bin/env python3
"""
PRISM Benchmark - Hugging Face Space
Phục vụ website HTML tĩnh qua Flask với CSS tối ưu cho bảng
"""
from flask import Flask, send_from_directory
import os
app = Flask(__name__, static_folder=".", static_url_path="")
# CSS tối ưu cho bảng
TABLE_CSS = """
<style>
/* Bảng Markdown */
table {
border-collapse: collapse;
width: 100%;
margin: 1.5rem 0;
font-size: 0.95rem;
line-height: 1.6;
}
table thead {
background-color: #f5f5f5;
border-bottom: 2px solid #ddd;
}
table th {
padding: 12px 16px;
text-align: left;
font-weight: 600;
color: #333;
border: 1px solid #ddd;
}
table td {
padding: 12px 16px;
border: 1px solid #ddd;
color: #555;
}
table tbody tr:nth-child(odd) {
background-color: #fafafa;
}
table tbody tr:hover {
background-color: #f0f0f0;
}
table tbody tr:nth-child(even) {
background-color: #fff;
}
/* Responsive table */
@media (max-width: 768px) {
table {
font-size: 0.85rem;
}
table th, table td {
padding: 8px 12px;
}
}
/* Đảm bảo bảng không bị cắt */
table {
word-wrap: break-word;
overflow-wrap: break-word;
}
table td, table th {
word-break: break-word;
}
</style>
"""
# Đọc index.html
with open("index.html", "r", encoding="utf-8") as f:
index_content = f.read()
# Thêm CSS vào head
if "</head>" in index_content:
index_content = index_content.replace("</head>", TABLE_CSS + "</head>")
@app.route("/")
def index():
return index_content
@app.route("/<path:filename>")
def serve_file(filename):
"""Phục vụ các file tĩnh"""
try:
return send_from_directory(".", filename)
except:
# Nếu file không tồn tại, trả về index.html
return index_content
@app.route("/demo/")
def demo():
"""Route cho demo page"""
demo_file = "demo/index.html"
if os.path.exists(demo_file):
with open(demo_file, "r", encoding="utf-8") as f:
content = f.read()
# Thêm CSS vào demo page
if "</head>" in content:
content = content.replace("</head>", TABLE_CSS + "</head>")
return content
return index_content
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860, debug=False)