Spaces:
Sleeping
Sleeping
import streamlit as st | |
from typing import Optional | |
import hashlib | |
import os | |
import pandas as pd | |
from .config import UPLOAD_FOLDER, DB_FOLDER | |
def init_folders(): | |
"""Initialize required folders""" | |
for folder in [UPLOAD_FOLDER, DB_FOLDER]: | |
os.makedirs(folder, exist_ok=True) | |
def get_file_hash(file_content: bytes) -> str: | |
"""Generate SHA-256 hash of file content""" | |
return hashlib.sha256(file_content).hexdigest() | |
def save_uploaded_file(uploaded_file) -> Optional[str]: | |
"""Save uploaded file and return the path""" | |
try: | |
file_path = os.path.join(UPLOAD_FOLDER, uploaded_file.name) | |
os.makedirs(os.path.dirname(file_path), exist_ok=True) | |
with open(file_path, "wb") as f: | |
f.write(uploaded_file.getvalue()) | |
return file_path | |
except Exception as e: | |
st.error(f"Error saving file: {str(e)}") | |
return None | |
def validate_csv_structure(df: pd.DataFrame) -> tuple[bool, list]: | |
"""Validate CSV file structure""" | |
required_columns = ['UnitCode', 'UnitType', 'Floor', 'Developer', 'TotalArea', 'AskingPrice', 'View'] | |
missing_columns = [col for col in required_columns if col not in df.columns] | |
return len(missing_columns) == 0, missing_columns | |