import streamlit as st import nbformat from nbconvert import PythonExporter import os import matplotlib import seaborn import sklearn # Load and execute the notebook file def execute_notebook(notebook_path): """Loads and executes the notebook, showing its content in the app.""" if not os.path.exists(notebook_path): st.error("Notebook file not found!") return st.markdown("### Executing Notebook") with open(notebook_path, "r") as f: notebook_content = f.read() # Convert notebook to Python script exporter = PythonExporter() python_code, _ = exporter.from_notebook_node(nbformat.reads(notebook_content, as_version=4)) # Execute the Python code dynamically try: exec(python_code, globals()) st.success("Notebook executed successfully!") except Exception as e: st.error(f"Error executing notebook: {e}") # Streamlit UI def main(): st.set_page_config(page_title="Notebook Runner", page_icon="📒", layout="wide") st.title("Notebook Runner App") notebook_file = "MLFlow Mentos Zindagi.ipynb" st.write(f"Loaded Notebook: **{notebook_file}**") if st.button("Run Notebook"): execute_notebook(notebook_file) if __name__ == "__main__": main()