Spaces:
Runtime error
Runtime error
Commit
·
9f7c458
1
Parent(s):
3f92c6c
add token debugging4
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
from modal import Function
|
4 |
import os
|
|
|
5 |
|
6 |
def init_modal():
|
7 |
"""Initialize Modal with token from environment"""
|
@@ -13,27 +14,55 @@ def init_modal():
|
|
13 |
st.info("Please add MODAL_TOKEN to Hugging Face Space secrets")
|
14 |
return False
|
15 |
|
16 |
-
# Create token file
|
17 |
token_dir = os.path.expanduser("~/.modal")
|
18 |
-
os.
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
f.write(token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
st.success("Modal token configured successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
return True
|
25 |
except Exception as e:
|
26 |
st.error(f"Failed to initialize Modal: {str(e)}")
|
|
|
27 |
return False
|
28 |
|
29 |
def main():
|
30 |
st.title("Financial Statement Analyzer")
|
31 |
|
32 |
-
# Show environment info
|
33 |
-
if st.checkbox("Show
|
34 |
-
|
35 |
st.write({k: "***" if k == "MODAL_TOKEN" else v
|
36 |
for k, v in os.environ.items()})
|
|
|
|
|
|
|
37 |
|
38 |
# Initialize Modal
|
39 |
if not init_modal():
|
@@ -78,7 +107,8 @@ def main():
|
|
78 |
status.error("Failed to extract financial data")
|
79 |
|
80 |
except Exception as e:
|
81 |
-
st.error(
|
|
|
82 |
progress_bar.empty()
|
83 |
|
84 |
if __name__ == "__main__":
|
|
|
2 |
import pandas as pd
|
3 |
from modal import Function
|
4 |
import os
|
5 |
+
import stat
|
6 |
|
7 |
def init_modal():
|
8 |
"""Initialize Modal with token from environment"""
|
|
|
14 |
st.info("Please add MODAL_TOKEN to Hugging Face Space secrets")
|
15 |
return False
|
16 |
|
17 |
+
# Create token file in user's home directory
|
18 |
token_dir = os.path.expanduser("~/.modal")
|
19 |
+
token_file = os.path.join(token_dir, "token")
|
20 |
|
21 |
+
# Create directory with proper permissions
|
22 |
+
os.makedirs(token_dir, mode=0o700, exist_ok=True)
|
23 |
+
|
24 |
+
# Write token file with proper permissions
|
25 |
+
with open(token_file, "w") as f:
|
26 |
f.write(token)
|
27 |
+
|
28 |
+
# Set file permissions to be readable only by owner
|
29 |
+
os.chmod(token_file, stat.S_IRUSR | stat.S_IWUSR)
|
30 |
+
|
31 |
+
# Verify the token file exists
|
32 |
+
if not os.path.exists(token_file):
|
33 |
+
st.error("Failed to create token file")
|
34 |
+
return False
|
35 |
|
36 |
st.success("Modal token configured successfully")
|
37 |
+
|
38 |
+
# Debug info
|
39 |
+
if st.checkbox("Show Token File Info"):
|
40 |
+
file_stat = os.stat(token_file)
|
41 |
+
st.write({
|
42 |
+
"Token file": token_file,
|
43 |
+
"Exists": os.path.exists(token_file),
|
44 |
+
"Permissions": oct(file_stat.st_mode)[-3:],
|
45 |
+
"Owner": file_stat.st_uid,
|
46 |
+
"Group": file_stat.st_gid
|
47 |
+
})
|
48 |
+
|
49 |
return True
|
50 |
except Exception as e:
|
51 |
st.error(f"Failed to initialize Modal: {str(e)}")
|
52 |
+
st.exception(e) # This will show the full traceback
|
53 |
return False
|
54 |
|
55 |
def main():
|
56 |
st.title("Financial Statement Analyzer")
|
57 |
|
58 |
+
# Show environment info
|
59 |
+
if st.checkbox("Show Environment Info"):
|
60 |
+
st.write("Environment Variables:")
|
61 |
st.write({k: "***" if k == "MODAL_TOKEN" else v
|
62 |
for k, v in os.environ.items()})
|
63 |
+
st.write("\nCurrent Working Directory:", os.getcwd())
|
64 |
+
st.write("User Home:", os.path.expanduser("~"))
|
65 |
+
st.write("User:", os.getenv("USER"))
|
66 |
|
67 |
# Initialize Modal
|
68 |
if not init_modal():
|
|
|
107 |
status.error("Failed to extract financial data")
|
108 |
|
109 |
except Exception as e:
|
110 |
+
st.error("Error during processing")
|
111 |
+
st.exception(e) # This will show the full traceback
|
112 |
progress_bar.empty()
|
113 |
|
114 |
if __name__ == "__main__":
|