math-ai-system / src /streamlit_app.py
Hebaelsayed's picture
Update src/streamlit_app.py
4e707f6 verified
raw
history blame
2.02 kB
import streamlit as st
import logging
from pathlib import Path
# ============================================================================
# SETUP
# ============================================================================
LOGS_DIR = Path("logs")
DATA_DIR = Path("data")
LOGS_DIR.mkdir(exist_ok=True)
DATA_DIR.mkdir(exist_ok=True)
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(LOGS_DIR / "app.log"),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
st.set_page_config(page_title="Math AI", layout="wide")
# ============================================================================
# STEP 2: FILE UPLOAD
# ============================================================================
st.title("๐Ÿงฎ Math AI System")
st.markdown("### Step 2: File Upload")
logger.info("App loaded")
# File upload
st.subheader("Upload a text file")
uploaded_file = st.file_uploader(
"Choose a text file",
type=["txt", "json"]
)
if uploaded_file:
logger.info(f"File uploaded: {uploaded_file.name}")
# Read file
content = uploaded_file.read().decode('utf-8')
st.success(f"โœ… File uploaded: {uploaded_file.name}")
st.write(f"Size: {len(content)} characters")
# Show preview
with st.expander("๐Ÿ“„ Preview (first 300 chars)"):
st.text(content[:300])
# Save to data folder
if st.button("๐Ÿ’พ Save to data folder"):
save_path = DATA_DIR / uploaded_file.name
with open(save_path, 'w') as f:
f.write(content)
logger.info(f"File saved to {save_path}")
st.success(f"โœ… Saved to data/{uploaded_file.name}")
# Show files in data folder
st.subheader("๐Ÿ“ Files in data folder")
files = list(DATA_DIR.glob("*"))
if files:
for f in files:
size_kb = f.stat().st_size / 1024
st.write(f"- {f.name} ({size_kb:.1f} KB)")
else:
st.info("No files yet. Upload one above!")