File size: 1,255 Bytes
12033a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""run the steamlit app through this python file"""

import os
import subprocess
import argparse

def ensure_folders_exist(script_dir):
    images_path = os.path.join(script_dir, "images")
    saved_model_path = os.path.join(script_dir, "saved_models")

    # Create the 'images' directory if it doesn't exist
    if not os.path.exists(images_path):
        os.makedirs(images_path)

    # Create the 'saved_model' directory if it doesn't exist
    if not os.path.exists(saved_model_path):
        os.makedirs(saved_model_path)

def run():
    parser = argparse.ArgumentParser()
    parser.add_argument("--port", type=int, default=8501,
                        help="Port number for the Streamlit app")
    args = parser.parse_args()

    # Get absolute path to the current script's directory
    script_dir = os.path.dirname(os.path.abspath(__file__))

    # Ensure that required folders exist
    ensure_folders_exist(script_dir)

    # Construct paths for app.py, images, and saved_model directories
    app_path = os.path.join(script_dir, "app.py")

    # Run the Streamlit app defined at app_path
    cmd = ["python", "-m", "streamlit", "run", "--server.port", str(args.port), app_path]
    subprocess.call(cmd)

if __name__ == "__main__":
    run()