Created
December 29, 2020 06:35
-
-
Save mengwangk/850819e4b6bb8934af9b38f82fe8f7e6 to your computer and use it in GitHub Desktop.
main.py - Serving ML Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from pathlib import Path | |
file = Path(__file__).resolve() | |
parent, root = file.parent, file.parents[1] | |
sys.path.append(str(root)) | |
try: | |
sys.path.remove(str(parent)) | |
except ValueError: | |
pass | |
import streamlit as st | |
import validators | |
from model.dcgan import dcgan | |
from model.pgan import pgan | |
from model.resnext import resnext | |
model_pages = { | |
"DCGAN": dcgan, | |
"PGAN": pgan, | |
"RESNEXT": resnext, | |
} | |
intro = """ | |
This app serves a number of machine learning models using FastAPI and Streamlit. | |
""" | |
def draw_main_page(): | |
st.write(f""" | |
# Welcome to my machine learning playground! 👋 | |
""") | |
st.write(intro) | |
st.info(""" | |
:point_left: **To get started, choose a model on the left sidebar.** | |
""") | |
# Draw sidebar | |
pages = list(model_pages.keys()) | |
pages.insert(0, "Home") | |
st.sidebar.title(f"Machine Learning Models") | |
selected_demo = st.sidebar.radio("", pages) | |
# Draw main page | |
if selected_demo in model_pages: | |
model_pages[selected_demo]() | |
else: | |
draw_main_page() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment