Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pandas as pd | |
| import os | |
| import modal | |
| from modal import Function | |
| def init_modal(): | |
| """Initialize Modal with direct token""" | |
| try: | |
| token = os.environ.get('MODAL_TOKEN') | |
| if not token: | |
| st.error("MODAL_TOKEN not found in environment variables") | |
| return False | |
| # Set Modal token directly | |
| modal.config.token = token | |
| st.success("Modal token set successfully") | |
| return True | |
| except Exception as e: | |
| st.error(f"Failed to initialize Modal: {str(e)}") | |
| st.exception(e) | |
| return False | |
| def main(): | |
| st.title("Financial Statement Analyzer") | |
| # Initialize Modal | |
| if not init_modal(): | |
| return | |
| uploaded_files = st.file_uploader( | |
| "Choose PDF files", | |
| type="pdf", | |
| accept_multiple_files=True, | |
| help="Upload Consolidated Financial Statements in Russian" | |
| ) | |
| if uploaded_files: | |
| for file in uploaded_files: | |
| with st.expander(f"Processing {file.name}", expanded=True): | |
| progress_bar = st.progress(0) | |
| status = st.empty() | |
| try: | |
| status.info("Starting PDF processing...") | |
| progress_bar.progress(25) | |
| # Process PDF through Modal backend | |
| pdf_processor = Function.lookup("stem", "process_pdf") | |
| financial_data = pdf_processor.remote(file) | |
| progress_bar.progress(75) | |
| if financial_data: | |
| # Display results in tabs | |
| tab1, tab2 = st.tabs(["Financial Ratios", "Raw Data"]) | |
| with tab1: | |
| st.subheader("Key Financial Ratios") | |
| st.dataframe(pd.DataFrame([financial_data])) | |
| with tab2: | |
| st.subheader("Extracted Financial Data") | |
| st.json(financial_data) | |
| status.success("Processing complete!") | |
| else: | |
| status.error("Failed to extract financial data") | |
| except Exception as e: | |
| st.error("Error during processing") | |
| st.exception(e) | |
| progress_bar.empty() | |
| if __name__ == "__main__": | |
| main() |