MilanM commited on
Commit
23bb2fd
·
verified ·
1 Parent(s): c56a578

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +193 -0
app.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ from io import BytesIO
5
+ import base64
6
+ import random
7
+ import io
8
+ import re
9
+ from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
10
+ from streamlit_tags import st_tags
11
+ from streamlit_vertical_slider import vertical_slider
12
+ import pdf_generator
13
+
14
+ # Set page config
15
+ st.set_page_config(
16
+ page_title="Pilot Drafting",
17
+ page_icon="🛫",
18
+ layout="wide",
19
+ initial_sidebar_state="collapsed"
20
+ )
21
+
22
+ # Password protection
23
+ def check_password():
24
+ def password_entered():
25
+ if st.session_state["password"] == st.secrets["app_password"]:
26
+ st.session_state["password_correct"] = True
27
+ del st.session_state["password"]
28
+ else:
29
+ st.session_state["password_correct"] = False
30
+
31
+ if "password_correct" not in st.session_state:
32
+ st.markdown("\n\n")
33
+ st.text_input("Enter the password", type="password", on_change=password_entered, key="password")
34
+ st.divider()
35
+ st.info("Developed by Milan Mrdenovic © IBM Norway 2024")
36
+ return False
37
+ elif not st.session_state["password_correct"]:
38
+ st.markdown("\n\n")
39
+ st.text_input("Enter the password", type="password", on_change=password_entered, key="password")
40
+ st.divider()
41
+ st.info("Developed by Milan Mrdenovic © IBM Norway 2024")
42
+ st.error("😕 Password incorrect")
43
+ return False
44
+ else:
45
+ return True
46
+
47
+ if not check_password():
48
+ st.stop()
49
+
50
+ # Initialize session state
51
+ if 'current_page' not in st.session_state:
52
+ st.session_state.current_page = 0
53
+
54
+ if 'answers' not in st.session_state:
55
+ st.session_state.answers = {
56
+ 'workload_scope': {
57
+ 'time_commitments': '',
58
+ 'deadlines': '',
59
+ 'feature_prioritization': ''
60
+ },
61
+ 'useful_assets': {
62
+ 'assets': []
63
+ },
64
+ 'pilot_evaluation': {
65
+ 'metrics': []
66
+ }
67
+ }
68
+
69
+ # Define the content for each page
70
+ pages = [
71
+ {
72
+ 'title': "Scope a Manageable Workload",
73
+ 'content': """
74
+ Define the scope of your project to ensure a manageable workload. Consider the time commitments, deadlines, and feature prioritization.
75
+ """,
76
+ 'input_key': 'workload_scope',
77
+ 'input_type': 'custom'
78
+ },
79
+ {
80
+ 'title': "Useful Assets and Libraries",
81
+ 'content': """
82
+ Discuss the useful assets and libraries that can be utilized for the project. Consider Langchain, Langflow, ChromaDB, Jupyter Notebooks, etc.
83
+ """,
84
+ 'input_key': 'useful_assets',
85
+ 'input_type': 'custom'
86
+ },
87
+ {
88
+ 'title': "Pilot Evaluation",
89
+ 'content': """
90
+ Plan for the metrics that need to be tracked for the project. Consider queries, token usage, F1 scores, precision, etc.
91
+ """,
92
+ 'input_key': 'pilot_evaluation',
93
+ 'input_type': 'custom'
94
+ },
95
+ {
96
+ 'title': "Generate Evaluation Report",
97
+ 'content': "You have completed the Pilot Drafting. \nClick the button below to generate and download your PDF report.",
98
+ 'input_key': None
99
+ }
100
+ ]
101
+
102
+ st.session_state.pages = pages
103
+
104
+ # Main Streamlit app
105
+ st.title("Pilot Drafting")
106
+
107
+ # Navigation buttons
108
+ col1, col2, col3 = st.columns([1, 2, 1])
109
+ with col1:
110
+ if st.session_state.current_page > 0:
111
+ if st.button("Back"):
112
+ st.session_state.current_page -= 1
113
+ st.rerun()
114
+ with col3:
115
+ if st.session_state.current_page < len(pages) - 1:
116
+ if st.button("Next", use_container_width=True):
117
+ st.session_state.current_page += 1
118
+ st.rerun()
119
+
120
+ # Display current page
121
+ current_page = pages[st.session_state.current_page]
122
+ st.header(current_page['title'])
123
+
124
+ with st.expander("Description", expanded=False):
125
+ st.markdown(current_page['content'])
126
+
127
+ # Input fields
128
+ if 'input_key' in current_page and current_page['input_key'] is not None:
129
+ if current_page['input_key'] == 'workload_scope':
130
+ st.subheader("Workload Scope")
131
+ col1, col2, col3 = st.columns(3)
132
+ with col1:
133
+ st.session_state.answers['workload_scope']['time_commitments'] = st.text_area(
134
+ "Time Commitments:",
135
+ value=st.session_state.answers['workload_scope'].get('time_commitments', ""),
136
+ key="time_commitments",
137
+ height=150
138
+ )
139
+ with col2:
140
+ st.session_state.answers['workload_scope']['deadlines'] = st.text_area(
141
+ "Deadlines:",
142
+ value=st.session_state.answers['workload_scope'].get('deadlines', ""),
143
+ key="deadlines",
144
+ height=150
145
+ )
146
+ with col3:
147
+ st.session_state.answers['workload_scope']['feature_prioritization'] = st.text_area(
148
+ "Feature Prioritization:",
149
+ value=st.session_state.answers['workload_scope'].get('feature_prioritization', ""),
150
+ key="feature_prioritization",
151
+ height=150
152
+ )
153
+
154
+ elif current_page['input_key'] == 'useful_assets':
155
+ st.subheader("Useful Assets and Libraries")
156
+ assets = st_tags(
157
+ label='Enter Useful Assets and Libraries:',
158
+ text='Press enter to add more',
159
+ value=st.session_state.answers['useful_assets'].get('assets', []),
160
+ suggestions=[],
161
+ maxtags=5,
162
+ key='useful_assets'
163
+ )
164
+ st.session_state.answers['useful_assets']['assets'] = assets
165
+
166
+ elif current_page['input_key'] == 'pilot_evaluation':
167
+ st.subheader("Pilot Evaluation")
168
+ metrics = st_tags(
169
+ label='Enter Metrics to Track:',
170
+ text='Press enter to add more',
171
+ value=st.session_state.answers['pilot_evaluation'].get('metrics', []),
172
+ suggestions=[],
173
+ maxtags=5,
174
+ key='pilot_evaluation'
175
+ )
176
+ st.session_state.answers['pilot_evaluation']['metrics'] = metrics
177
+
178
+ # Generate PDF button (only on the last page)
179
+ if st.session_state.current_page == len(pages) - 1:
180
+ if st.button("Generate and Download PDF", use_container_width=True):
181
+ pdf = pdf_generator.generate_pdf(st.session_state)
182
+ st.download_button(
183
+ label="Download PDF",
184
+ data=pdf,
185
+ file_name="Pilot_Drafting.pdf",
186
+ mime="application/pdf",
187
+ use_container_width=True
188
+ )
189
+
190
+ # Display progress
191
+ st.progress((st.session_state.current_page + 1) / len(pages))
192
+
193
+ st.divider()