Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,13 @@ from PIL import Image
|
|
| 10 |
import fitz # PyMuPDF
|
| 11 |
import time
|
| 12 |
import re
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Set page configuration
|
| 16 |
st.set_page_config(
|
|
@@ -328,6 +334,18 @@ st.markdown("""
|
|
| 328 |
background-color: #1177bb;
|
| 329 |
}
|
| 330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
/* Editor tab bar */
|
| 332 |
.tab-bar {
|
| 333 |
display: flex;
|
|
@@ -675,6 +693,12 @@ st.markdown("""
|
|
| 675 |
border: 1px solid #2d2d2d;
|
| 676 |
border-radius: 4px;
|
| 677 |
overflow: hidden;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 678 |
}
|
| 679 |
</style>
|
| 680 |
""", unsafe_allow_html=True)
|
|
@@ -943,48 +967,51 @@ def main():
|
|
| 943 |
snippet_to_insert = ""
|
| 944 |
|
| 945 |
if st.session_state.get("btn_bold", False):
|
| 946 |
-
|
| 947 |
-
|
| 948 |
elif st.session_state.get("btn_italic", False):
|
| 949 |
-
|
| 950 |
-
|
| 951 |
elif st.session_state.get("btn_section", False):
|
| 952 |
-
|
| 953 |
-
|
| 954 |
elif st.session_state.get("btn_subsection", False):
|
| 955 |
-
|
| 956 |
-
|
| 957 |
elif st.session_state.get("btn_itemize", False):
|
| 958 |
-
|
| 959 |
-
|
| 960 |
elif st.session_state.get("btn_enumerate", False):
|
| 961 |
-
|
| 962 |
-
|
| 963 |
elif st.session_state.get("btn_equation", False):
|
| 964 |
-
|
| 965 |
-
|
| 966 |
elif st.session_state.get("btn_table", False):
|
| 967 |
-
|
| 968 |
-
|
| 969 |
|
| 970 |
-
#
|
| 971 |
-
# Monaco Editor with LaTeX configuration
|
| 972 |
st.markdown('<div class="monaco-editor-container">', unsafe_allow_html=True)
|
| 973 |
-
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 982 |
|
| 983 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 984 |
|
| 985 |
-
if latex_code is not None:
|
| 986 |
-
st.session_state.latex_code = latex_code
|
| 987 |
-
|
| 988 |
# Status bar
|
| 989 |
render_status_bar()
|
| 990 |
|
|
|
|
| 10 |
import fitz # PyMuPDF
|
| 11 |
import time
|
| 12 |
import re
|
| 13 |
+
|
| 14 |
+
# Try to import streamlit-monaco
|
| 15 |
+
try:
|
| 16 |
+
from streamlit_monaco import st_monaco
|
| 17 |
+
MONACO_AVAILABLE = True
|
| 18 |
+
except ImportError:
|
| 19 |
+
MONACO_AVAILABLE = False
|
| 20 |
|
| 21 |
# Set page configuration
|
| 22 |
st.set_page_config(
|
|
|
|
| 334 |
background-color: #1177bb;
|
| 335 |
}
|
| 336 |
|
| 337 |
+
/* VS Code-like editor styling */
|
| 338 |
+
.stTextArea textarea {
|
| 339 |
+
font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
|
| 340 |
+
font-size: 14px !important;
|
| 341 |
+
line-height: 1.5 !important;
|
| 342 |
+
background-color: #1e1e1e !important;
|
| 343 |
+
color: #d4d4d4 !important;
|
| 344 |
+
padding: 10px !important;
|
| 345 |
+
border-radius: 4px !important;
|
| 346 |
+
border: 1px solid #252526 !important;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
/* Editor tab bar */
|
| 350 |
.tab-bar {
|
| 351 |
display: flex;
|
|
|
|
| 693 |
border: 1px solid #2d2d2d;
|
| 694 |
border-radius: 4px;
|
| 695 |
overflow: hidden;
|
| 696 |
+
margin-bottom: 10px;
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
/* Make sure Monaco editor has correct background */
|
| 700 |
+
.monaco-editor, .monaco-editor-background, .monaco-editor .margin {
|
| 701 |
+
background-color: #1e1e1e !important;
|
| 702 |
}
|
| 703 |
</style>
|
| 704 |
""", unsafe_allow_html=True)
|
|
|
|
| 967 |
snippet_to_insert = ""
|
| 968 |
|
| 969 |
if st.session_state.get("btn_bold", False):
|
| 970 |
+
st.session_state.latex_code += "\\textbf{}"
|
| 971 |
+
st.rerun()
|
| 972 |
elif st.session_state.get("btn_italic", False):
|
| 973 |
+
st.session_state.latex_code += "\\textit{}"
|
| 974 |
+
st.rerun()
|
| 975 |
elif st.session_state.get("btn_section", False):
|
| 976 |
+
st.session_state.latex_code += "\\section{}"
|
| 977 |
+
st.rerun()
|
| 978 |
elif st.session_state.get("btn_subsection", False):
|
| 979 |
+
st.session_state.latex_code += "\\subsection{}"
|
| 980 |
+
st.rerun()
|
| 981 |
elif st.session_state.get("btn_itemize", False):
|
| 982 |
+
st.session_state.latex_code += "\\begin{itemize}\n \\item \n\\end{itemize}"
|
| 983 |
+
st.rerun()
|
| 984 |
elif st.session_state.get("btn_enumerate", False):
|
| 985 |
+
st.session_state.latex_code += "\\begin{enumerate}\n \\item \n\\end{enumerate}"
|
| 986 |
+
st.rerun()
|
| 987 |
elif st.session_state.get("btn_equation", False):
|
| 988 |
+
st.session_state.latex_code += "\\begin{equation}\n \n\\end{equation}"
|
| 989 |
+
st.rerun()
|
| 990 |
elif st.session_state.get("btn_table", False):
|
| 991 |
+
st.session_state.latex_code += "\\begin{table}[h]\n \\centering\n \\begin{tabular}{ccc}\n A & B & C \\\\\n 1 & 2 & 3 \\\\\n \\end{tabular}\n \\caption{Caption}\n \\label{tab:label}\n\\end{table}"
|
| 992 |
+
st.rerun()
|
| 993 |
|
| 994 |
+
# Editor with Monaco or fallback to text area
|
|
|
|
| 995 |
st.markdown('<div class="monaco-editor-container">', unsafe_allow_html=True)
|
| 996 |
+
|
| 997 |
+
if MONACO_AVAILABLE:
|
| 998 |
+
try:
|
| 999 |
+
# Try to use Monaco editor with minimal parameters
|
| 1000 |
+
latex_code = st_monaco(st.session_state.latex_code, height=500)
|
| 1001 |
+
if latex_code is not None:
|
| 1002 |
+
st.session_state.latex_code = latex_code
|
| 1003 |
+
except Exception as e:
|
| 1004 |
+
# Fallback to text area if Monaco fails
|
| 1005 |
+
st.warning(f"Monaco editor unavailable: {str(e)}")
|
| 1006 |
+
latex_code = st.text_area("", value=st.session_state.latex_code, height=500, key="latex_editor", label_visibility="collapsed")
|
| 1007 |
+
st.session_state.latex_code = latex_code
|
| 1008 |
+
else:
|
| 1009 |
+
# Fallback to regular text area
|
| 1010 |
+
latex_code = st.text_area("", value=st.session_state.latex_code, height=500, key="latex_editor", label_visibility="collapsed")
|
| 1011 |
+
st.session_state.latex_code = latex_code
|
| 1012 |
|
| 1013 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 1014 |
|
|
|
|
|
|
|
|
|
|
| 1015 |
# Status bar
|
| 1016 |
render_status_bar()
|
| 1017 |
|