pentarosarium commited on
Commit
cba456b
·
1 Parent(s): d88bf1f

new modal init

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -6,8 +6,19 @@ import os
6
  def init_modal():
7
  """Initialize Modal with token from environment"""
8
  try:
9
- from modal.config import config
10
- config.cli.token = os.environ.get('MODAL_TOKEN')
 
 
 
 
 
 
 
 
 
 
 
11
  return True
12
  except Exception as e:
13
  st.error(f"Failed to initialize Modal: {str(e)}")
@@ -16,13 +27,9 @@ def init_modal():
16
  def main():
17
  st.title("Financial Statement Analyzer")
18
 
19
- # Check Modal token
20
- if 'MODAL_TOKEN' not in os.environ:
21
- st.error("Modal token not found. Please add MODAL_TOKEN to Space secrets.")
22
- return
23
-
24
  # Initialize Modal
25
  if not init_modal():
 
26
  return
27
 
28
  uploaded_files = st.file_uploader(
@@ -64,8 +71,7 @@ def main():
64
  status.error("Failed to extract financial data")
65
 
66
  except Exception as e:
67
- status.error(f"Error: {str(e)}")
68
- st.error("Full error message: " + str(e))
69
  progress_bar.empty()
70
 
71
  if __name__ == "__main__":
 
6
  def init_modal():
7
  """Initialize Modal with token from environment"""
8
  try:
9
+ # Import modal and directly set token from environment
10
+ import modal
11
+ token = os.environ.get('MODAL_TOKEN')
12
+ if not token:
13
+ raise ValueError("MODAL_TOKEN environment variable not set")
14
+
15
+ # Create token file
16
+ token_dir = os.path.expanduser("~/.modal")
17
+ os.makedirs(token_dir, exist_ok=True)
18
+
19
+ with open(os.path.join(token_dir, "token"), "w") as f:
20
+ f.write(token)
21
+
22
  return True
23
  except Exception as e:
24
  st.error(f"Failed to initialize Modal: {str(e)}")
 
27
  def main():
28
  st.title("Financial Statement Analyzer")
29
 
 
 
 
 
 
30
  # Initialize Modal
31
  if not init_modal():
32
+ st.error("Could not initialize Modal. Please check your token configuration.")
33
  return
34
 
35
  uploaded_files = st.file_uploader(
 
71
  status.error("Failed to extract financial data")
72
 
73
  except Exception as e:
74
+ st.error(f"Error during processing: {str(e)}")
 
75
  progress_bar.empty()
76
 
77
  if __name__ == "__main__":