Spaces:
Sleeping
Sleeping
DEBUG: font replacement for unicode chars
Browse files- main.py +17 -2
- src/utils/logger.py +1 -0
main.py
CHANGED
|
@@ -4,6 +4,8 @@ import streamlit as st
|
|
| 4 |
from io import BytesIO
|
| 5 |
from fpdf import FPDF
|
| 6 |
import time
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Configure the page
|
| 9 |
st.set_page_config(
|
|
@@ -37,6 +39,16 @@ st.markdown("""
|
|
| 37 |
</style>
|
| 38 |
""", unsafe_allow_html=True)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Sidebar
|
| 41 |
with st.sidebar:
|
| 42 |
st.markdown("### Upload PDF")
|
|
@@ -91,12 +103,15 @@ if uploadedFile:
|
|
| 91 |
|
| 92 |
if st.button("Download Summary as PDF"):
|
| 93 |
try:
|
|
|
|
|
|
|
| 94 |
pdf = FPDF()
|
| 95 |
pdf.add_page()
|
| 96 |
-
pdf.
|
|
|
|
| 97 |
pdf.cell(200, 10, txt="PDF Summary", ln=True, align='C')
|
| 98 |
pdf.ln(10)
|
| 99 |
-
pdf.set_font("
|
| 100 |
pdf.multi_cell(0, 10, summary)
|
| 101 |
|
| 102 |
pdfOutput = BytesIO()
|
|
|
|
| 4 |
from io import BytesIO
|
| 5 |
from fpdf import FPDF
|
| 6 |
import time
|
| 7 |
+
import requests
|
| 8 |
+
import tempfile
|
| 9 |
|
| 10 |
# Configure the page
|
| 11 |
st.set_page_config(
|
|
|
|
| 39 |
</style>
|
| 40 |
""", unsafe_allow_html=True)
|
| 41 |
|
| 42 |
+
# Cache the font download
|
| 43 |
+
@st.cache_resource(show_spinner=False)
|
| 44 |
+
def get_dejavu_font_path():
|
| 45 |
+
FONT_URL = "https://github.com/dejavu-fonts/dejavu-fonts/raw/version_2_37/ttf/DejaVuSans.ttf"
|
| 46 |
+
response = requests.get(FONT_URL)
|
| 47 |
+
tempFontFile = tempfile.NamedTemporaryFile(delete=False, suffix=".ttf")
|
| 48 |
+
tempFontFile.write(response.content)
|
| 49 |
+
tempFontFile.close()
|
| 50 |
+
return tempFontFile.name
|
| 51 |
+
|
| 52 |
# Sidebar
|
| 53 |
with st.sidebar:
|
| 54 |
st.markdown("### Upload PDF")
|
|
|
|
| 103 |
|
| 104 |
if st.button("Download Summary as PDF"):
|
| 105 |
try:
|
| 106 |
+
font_path = get_dejavu_font_path()
|
| 107 |
+
|
| 108 |
pdf = FPDF()
|
| 109 |
pdf.add_page()
|
| 110 |
+
pdf.add_font("DejaVu", "", font_path, uni=True)
|
| 111 |
+
pdf.set_font("DejaVu", '', 16)
|
| 112 |
pdf.cell(200, 10, txt="PDF Summary", ln=True, align='C')
|
| 113 |
pdf.ln(10)
|
| 114 |
+
pdf.set_font("DejaVu", '', 12)
|
| 115 |
pdf.multi_cell(0, 10, summary)
|
| 116 |
|
| 117 |
pdfOutput = BytesIO()
|
src/utils/logger.py
CHANGED
|
@@ -6,5 +6,6 @@ logFilePath = os.path.join(os.getcwd(), "logs", "runningLogs.log")
|
|
| 6 |
logFormat = "<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
|
| 7 |
|
| 8 |
logger.remove()
|
|
|
|
| 9 |
logger.add(sys.stdout, colorize = True, format = logFormat)
|
| 10 |
logger.add(logFilePath, format = logFormat, enqueue = True, mode = "w")
|
|
|
|
| 6 |
logFormat = "<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
|
| 7 |
|
| 8 |
logger.remove()
|
| 9 |
+
|
| 10 |
logger.add(sys.stdout, colorize = True, format = logFormat)
|
| 11 |
logger.add(logFilePath, format = logFormat, enqueue = True, mode = "w")
|