Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,21 @@
|
|
1 |
import os
|
2 |
import sys
|
3 |
import streamlit as st
|
|
|
4 |
|
5 |
# Mendapatkan isi script dari environment variable
|
6 |
-
|
7 |
|
8 |
-
if
|
9 |
st.error("Environment variable 'MY_SCRIPT_CONTENT' not set.")
|
10 |
sys.exit(1)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Menjalankan script dinamis
|
13 |
exec(script_content)
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
import streamlit as st
|
4 |
+
import ast
|
5 |
|
6 |
# Mendapatkan isi script dari environment variable
|
7 |
+
script_repr = os.getenv("MY_SCRIPT_CONTENT")
|
8 |
|
9 |
+
if script_repr is None:
|
10 |
st.error("Environment variable 'MY_SCRIPT_CONTENT' not set.")
|
11 |
sys.exit(1)
|
12 |
|
13 |
+
# Mengevaluasi string literal dengan aman
|
14 |
+
try:
|
15 |
+
script_content = ast.literal_eval(script_repr)
|
16 |
+
except (ValueError, SyntaxError) as e:
|
17 |
+
st.error(f"Error evaluating script from environment variable: {e}")
|
18 |
+
sys.exit(1)
|
19 |
+
|
20 |
# Menjalankan script dinamis
|
21 |
exec(script_content)
|