-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstreamlit_app.py
135 lines (111 loc) Β· 3.95 KB
/
streamlit_app.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import streamlit as st
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__))))
from apps import common_header
from apps import (
bistro_game,
global_optimization,
batch_process,
facility_location,
supply_chain,
aircrew_training_scheduling,
risk_return,
optimal_control,
nqueens,
sudoku,
tips,
python,
reformulation_explorer,
)
st.set_page_config(
page_title="AMPL on Streamlit Cloud",
page_icon="./static/images/cropped-favicon-raw-192x192.png",
)
@st.cache_data
def activate_license():
from amplpy import modules
# Activate the license (e.g., a free https://ampl.com/ce license)
uuid = os.environ.get("AMPLKEY_UUID", None)
if uuid is not None:
modules.activate(uuid)
return uuid
activate_license()
def home():
st.write("# Welcome to AMPL on Streamlit! π")
st.markdown(
"""
[AMPL](https://ampl.com) is the most powerful and intuitive tool for developing and deploying
complex optimization solutions in business & scientific applications.
"""
)
st.success(
"**π Select an app from the sidebar** to see some examples of what you can do with AMPL on Streamlit!"
)
app_list = ""
for group in pages:
app_list += f"- {group}\n"
for page in pages[group]:
if page.url_path == "":
continue
app_list += f" - [{page.icon} {page.title}](/{page.url_path})\n"
st.markdown(app_list)
st.markdown(
"""
- [π Documentation](https://dev.ampl.com/)
- [π¬ Support Forum](https://discuss.ampl.com/)
- [π§βπ€βπ§ Model Colaboratory](https://ampl.com/colab/)
Follow us on [LinkedIn](https://www.linkedin.com/company/ampl) and [Twitter](https://twitter.com/AMPLopt) to get the latest updates from the dev team!
"""
)
python.main()
st.markdown(
"""
[[App Source Code on GitHub](https://github.com/fdabrandao/amplopt.streamlit.app/tree/master/apps/tips)]
[[Build your own App with AMPL & Streamlit](https://dev.ampl.com/ampl/python/streamlit.html)]
"""
)
def app_page(app, icon, title, url_path=None):
if url_path is None:
url_path = title.replace(" ", "_")
if title == "Home":
url_path = ""
def page():
common_header(url_path)
app()
st.markdown(
"[AMPL Website](https://ampl.com) | [Follow us on LinkedIn](https://www.linkedin.com/company/ampl) | [Documentation](https://dev.ampl.com) | [Colab Notebooks](https://ampl.com/colab) | [MO-Book](https://ampl.com/mo-book)"
)
return st.Page(
page,
url_path=url_path,
title=title,
icon=icon,
default=url_path == "",
)
pages = {
"AMPL Streamlit Apps": [
app_page(home, "π ", "Home"),
app_page(tips.main, "π‘", "Modeling Tips"),
],
"Applications": [
app_page(aircrew_training_scheduling.main, "βοΈ", "Aircrew Training Scheduling"),
app_page(batch_process.main, "βοΈ", "Batch Process Optimization"),
app_page(facility_location.main, "π", "Stochastic Facility Location"),
app_page(supply_chain.main, "π¦", "Supply Chain Optimization"),
app_page(risk_return.main, "π", "Portfolio Optimization", "Risk_Return"),
app_page(tips.main_tip7, "π·οΈ", "Logistic Regression"),
app_page(optimal_control.main, "π―", "Optimal Control"),
],
"Puzzles & Games": [
app_page(nqueens.main, "π", "N-Queens"),
app_page(sudoku.main, "π’", "Sudoku"),
app_page(bistro_game.main, "π½οΈ", "Bistro Game"),
app_page(global_optimization.main, "π
", "Global Optimization"),
],
"Tools & Documentation": [
app_page(python.main, "π", "Python Integration"),
app_page(reformulation_explorer.main, "π", "Reformulation Explorer"),
],
}
st.navigation(pages).run()