Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,35 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import os
|
| 3 |
import sys
|
|
|
|
| 4 |
from tempfile import NamedTemporaryFile
|
| 5 |
-
import traceback
|
| 6 |
|
| 7 |
def main():
|
| 8 |
-
st.set_page_config(
|
| 9 |
-
page_title="ACE Singer",
|
| 10 |
-
page_icon="🎵",
|
| 11 |
-
layout="wide"
|
| 12 |
-
)
|
| 13 |
-
|
| 14 |
-
st.title("🎵 ACE Singer")
|
| 15 |
-
|
| 16 |
try:
|
| 17 |
-
# Get the code from
|
| 18 |
code = os.environ.get("MAIN_CODE")
|
| 19 |
|
| 20 |
if not code:
|
| 21 |
-
st.error("⚠️ The application code wasn't found in
|
| 22 |
-
st.info("Please set the MAIN_CODE environment variable with your application code.")
|
| 23 |
return
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
'__name__': '__main__',
|
| 30 |
-
'st': st,
|
| 31 |
-
'os': os,
|
| 32 |
-
'sys': sys
|
| 33 |
-
}
|
| 34 |
|
| 35 |
-
|
|
|
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
except Exception as e:
|
| 38 |
st.error(f"⚠️ Error loading or executing the application: {str(e)}")
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
| 43 |
main()
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
+
import streamlit as st
|
| 4 |
from tempfile import NamedTemporaryFile
|
|
|
|
| 5 |
|
| 6 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
try:
|
| 8 |
+
# Get the code from secrets
|
| 9 |
code = os.environ.get("MAIN_CODE")
|
| 10 |
|
| 11 |
if not code:
|
| 12 |
+
st.error("⚠️ The application code wasn't found in secrets. Please add the MAIN_CODE secret.")
|
|
|
|
| 13 |
return
|
| 14 |
|
| 15 |
+
# Create a temporary Python file
|
| 16 |
+
with NamedTemporaryFile(suffix='.py', delete=False, mode='w') as tmp:
|
| 17 |
+
tmp.write(code)
|
| 18 |
+
tmp_path = tmp.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Execute the code
|
| 21 |
+
exec(compile(code, tmp_path, 'exec'), globals())
|
| 22 |
|
| 23 |
+
# Clean up the temporary file
|
| 24 |
+
try:
|
| 25 |
+
os.unlink(tmp_path)
|
| 26 |
+
except:
|
| 27 |
+
pass
|
| 28 |
+
|
| 29 |
except Exception as e:
|
| 30 |
st.error(f"⚠️ Error loading or executing the application: {str(e)}")
|
| 31 |
+
import traceback
|
| 32 |
+
st.code(traceback.format_exc())
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
main()
|