Prathamesh1420 commited on
Commit
87dd824
·
verified ·
1 Parent(s): 237d7a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import nbformat
3
+ from nbconvert import PythonExporter
4
+ import os
5
+
6
+ # Load and execute the notebook file
7
+ def execute_notebook(notebook_path):
8
+ """Loads and executes the notebook, showing its content in the app."""
9
+ if not os.path.exists(notebook_path):
10
+ st.error("Notebook file not found!")
11
+ return
12
+
13
+ st.markdown("### Executing Notebook")
14
+ with open(notebook_path, "r") as f:
15
+ notebook_content = f.read()
16
+
17
+ # Convert notebook to Python script
18
+ exporter = PythonExporter()
19
+ python_code, _ = exporter.from_notebook_node(nbformat.reads(notebook_content, as_version=4))
20
+
21
+ # Execute the Python code dynamically
22
+ try:
23
+ exec(python_code, globals())
24
+ st.success("Notebook executed successfully!")
25
+ except Exception as e:
26
+ st.error(f"Error executing notebook: {e}")
27
+
28
+ # Streamlit UI
29
+ def main():
30
+ st.set_page_config(page_title="Notebook Runner", page_icon="📒", layout="wide")
31
+ st.title("Notebook Runner App")
32
+
33
+ notebook_file = "MLFlow Mentos Zindagi.ipynb"
34
+ st.write(f"Loaded Notebook: **{notebook_file}**")
35
+
36
+ if st.button("Run Notebook"):
37
+ execute_notebook(notebook_file)
38
+
39
+ if __name__ == "__main__":
40
+ main()