ruslanmv commited on
Commit
80b4858
·
1 Parent(s): b6feb0d

First commit

Browse files
Files changed (2) hide show
  1. .gitignore +4 -0
  2. app.py +15 -12
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ main.py
3
+ encode.sh
4
+ encoded_app.txt
app.py CHANGED
@@ -1,16 +1,19 @@
1
  import os
 
 
2
 
3
- if __name__ == "__main__":
4
- # Get the file path from the environment variable `APP`
5
- app_file_path = os.getenv("APP")
 
 
6
 
7
- if not app_file_path:
8
- raise ValueError("The environment variable 'APP' is not set.")
9
 
10
- try:
11
- # Execute the specified app file
12
- exec(open(app_file_path).read())
13
- except FileNotFoundError as e:
14
- raise FileNotFoundError(f"The file '{app_file_path}' could not be found.") from e
15
- except Exception as e:
16
- raise RuntimeError(f"An error occurred while running the app: {e}") from e
 
1
  import os
2
+ import base64
3
+ import gradio as gr
4
 
5
+ # Load the APP environment variable
6
+ app_code = os.getenv("APP")
7
+
8
+ if not app_code:
9
+ raise ValueError("The APP environment variable is not set.")
10
 
11
+ # Decode the app_code (assuming it's encoded, e.g., using Base64)
12
+ decoded_app_code = base64.b64decode(app_code).decode("utf-8")
13
 
14
+ # Execute the decoded code in the global scope
15
+ exec(decoded_app_code)
16
+
17
+ # If the code contains a Gradio app (like `demo`), it will launch when executed
18
+ if __name__ == "__main__":
19
+ demo.launch()