Spaces:
Runtime error
Runtime error
Commit ·
c228a82
1
Parent(s): 2c5fe24
add config
Browse files- app.py +30 -28
- requirements.txt +1 -2
app.py
CHANGED
|
@@ -1,35 +1,35 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
-
from modal import
|
| 5 |
-
import
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
"""Initialize Modal
|
| 9 |
try:
|
| 10 |
token = os.environ.get('MODAL_TOKEN')
|
| 11 |
if not token:
|
| 12 |
st.error("MODAL_TOKEN not found in environment variables")
|
| 13 |
-
return
|
| 14 |
-
|
| 15 |
-
# Create Modal client with token
|
| 16 |
-
client = asyncio.run(Client.from_token(token))
|
| 17 |
-
return client
|
| 18 |
-
except Exception as e:
|
| 19 |
-
st.error(f"Failed to initialize Modal client: {str(e)}")
|
| 20 |
-
st.exception(e)
|
| 21 |
-
return None
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
except Exception as e:
|
| 30 |
-
st.error(f"
|
| 31 |
st.exception(e)
|
| 32 |
-
return
|
| 33 |
|
| 34 |
def main():
|
| 35 |
st.title("Financial Statement Analyzer")
|
|
@@ -39,15 +39,16 @@ def main():
|
|
| 39 |
st.write("Environment Variables:")
|
| 40 |
st.write({k: "***" if k == "MODAL_TOKEN" else v
|
| 41 |
for k, v in os.environ.items()})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
# Initialize Modal
|
| 44 |
-
|
| 45 |
-
if client is None:
|
| 46 |
-
st.error("Could not initialize Modal client")
|
| 47 |
return
|
| 48 |
|
| 49 |
-
st.success("Modal client initialized successfully")
|
| 50 |
-
|
| 51 |
uploaded_files = st.file_uploader(
|
| 52 |
"Choose PDF files",
|
| 53 |
type="pdf",
|
|
@@ -66,7 +67,8 @@ def main():
|
|
| 66 |
progress_bar.progress(25)
|
| 67 |
|
| 68 |
# Process PDF through Modal backend
|
| 69 |
-
|
|
|
|
| 70 |
progress_bar.progress(75)
|
| 71 |
|
| 72 |
if financial_data:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
+
from modal import Function
|
| 5 |
+
from pathlib import Path
|
| 6 |
|
| 7 |
+
def init_modal():
|
| 8 |
+
"""Initialize Modal with token"""
|
| 9 |
try:
|
| 10 |
token = os.environ.get('MODAL_TOKEN')
|
| 11 |
if not token:
|
| 12 |
st.error("MODAL_TOKEN not found in environment variables")
|
| 13 |
+
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Create .modal directory
|
| 16 |
+
modal_dir = Path.home() / '.modal'
|
| 17 |
+
modal_dir.mkdir(exist_ok=True)
|
| 18 |
+
|
| 19 |
+
# Create config.toml file
|
| 20 |
+
config_path = modal_dir / 'config.toml'
|
| 21 |
+
config_content = f'''[default]
|
| 22 |
+
token = "{token}"
|
| 23 |
+
'''
|
| 24 |
+
config_path.write_text(config_content)
|
| 25 |
+
|
| 26 |
+
st.success("Modal configuration created successfully")
|
| 27 |
+
return True
|
| 28 |
+
|
| 29 |
except Exception as e:
|
| 30 |
+
st.error(f"Failed to initialize Modal: {str(e)}")
|
| 31 |
st.exception(e)
|
| 32 |
+
return False
|
| 33 |
|
| 34 |
def main():
|
| 35 |
st.title("Financial Statement Analyzer")
|
|
|
|
| 39 |
st.write("Environment Variables:")
|
| 40 |
st.write({k: "***" if k == "MODAL_TOKEN" else v
|
| 41 |
for k, v in os.environ.items()})
|
| 42 |
+
|
| 43 |
+
# Show Modal config if it exists
|
| 44 |
+
config_path = Path.home() / '.modal' / 'config.toml'
|
| 45 |
+
if config_path.exists():
|
| 46 |
+
st.write("Modal config exists at:", str(config_path))
|
| 47 |
|
| 48 |
+
# Initialize Modal
|
| 49 |
+
if not init_modal():
|
|
|
|
|
|
|
| 50 |
return
|
| 51 |
|
|
|
|
|
|
|
| 52 |
uploaded_files = st.file_uploader(
|
| 53 |
"Choose PDF files",
|
| 54 |
type="pdf",
|
|
|
|
| 67 |
progress_bar.progress(25)
|
| 68 |
|
| 69 |
# Process PDF through Modal backend
|
| 70 |
+
pdf_processor = Function.lookup("stem", "process_pdf")
|
| 71 |
+
financial_data = pdf_processor.remote(file)
|
| 72 |
progress_bar.progress(75)
|
| 73 |
|
| 74 |
if financial_data:
|
requirements.txt
CHANGED
|
@@ -2,5 +2,4 @@ modal
|
|
| 2 |
streamlit>=1.32.0
|
| 3 |
pandas>=2.2.0
|
| 4 |
python-dotenv>=1.0.0
|
| 5 |
-
|
| 6 |
-
aiohttp
|
|
|
|
| 2 |
streamlit>=1.32.0
|
| 3 |
pandas>=2.2.0
|
| 4 |
python-dotenv>=1.0.0
|
| 5 |
+
toml
|
|
|