File size: 6,493 Bytes
23bb2fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
from io import BytesIO
import base64
import random
import io
import re
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from streamlit_tags import st_tags
from streamlit_vertical_slider import vertical_slider
import pdf_generator

# Set page config
st.set_page_config(
    page_title="Pilot Drafting",
    page_icon="🛫",
    layout="wide",
    initial_sidebar_state="collapsed"
)

# Password protection
def check_password():
    def password_entered():
        if st.session_state["password"] == st.secrets["app_password"]:
            st.session_state["password_correct"] = True
            del st.session_state["password"]
        else:
            st.session_state["password_correct"] = False

    if "password_correct" not in st.session_state:
        st.markdown("\n\n")
        st.text_input("Enter the password", type="password", on_change=password_entered, key="password")
        st.divider()
        st.info("Developed by Milan Mrdenovic © IBM Norway 2024")
        return False
    elif not st.session_state["password_correct"]:
        st.markdown("\n\n")
        st.text_input("Enter the password", type="password", on_change=password_entered, key="password")
        st.divider()
        st.info("Developed by Milan Mrdenovic © IBM Norway 2024")
        st.error("😕 Password incorrect")
        return False
    else:
        return True

if not check_password():
    st.stop()

# Initialize session state
if 'current_page' not in st.session_state:
    st.session_state.current_page = 0

if 'answers' not in st.session_state:
    st.session_state.answers = {
        'workload_scope': {
            'time_commitments': '',
            'deadlines': '',
            'feature_prioritization': ''
        },
        'useful_assets': {
            'assets': []
        },
        'pilot_evaluation': {
            'metrics': []
        }
    }

# Define the content for each page
pages = [
    {
        'title': "Scope a Manageable Workload",
        'content': """
        Define the scope of your project to ensure a manageable workload. Consider the time commitments, deadlines, and feature prioritization.
        """,
        'input_key': 'workload_scope',
        'input_type': 'custom'
    },
    {
        'title': "Useful Assets and Libraries",
        'content': """
        Discuss the useful assets and libraries that can be utilized for the project. Consider Langchain, Langflow, ChromaDB, Jupyter Notebooks, etc.
        """,
        'input_key': 'useful_assets',
        'input_type': 'custom'
    },
    {
        'title': "Pilot Evaluation",
        'content': """
        Plan for the metrics that need to be tracked for the project. Consider queries, token usage, F1 scores, precision, etc.
        """,
        'input_key': 'pilot_evaluation',
        'input_type': 'custom'
    },
    {
        'title': "Generate Evaluation Report",
        'content': "You have completed the Pilot Drafting. \nClick the button below to generate and download your PDF report.",
        'input_key': None
    }
]

st.session_state.pages = pages

# Main Streamlit app
st.title("Pilot Drafting")

# Navigation buttons
col1, col2, col3 = st.columns([1, 2, 1])
with col1:
    if st.session_state.current_page > 0:
        if st.button("Back"):
            st.session_state.current_page -= 1
            st.rerun()
with col3:
    if st.session_state.current_page < len(pages) - 1:
        if st.button("Next", use_container_width=True):
            st.session_state.current_page += 1
            st.rerun()

# Display current page
current_page = pages[st.session_state.current_page]
st.header(current_page['title'])

with st.expander("Description", expanded=False):
    st.markdown(current_page['content'])

# Input fields
if 'input_key' in current_page and current_page['input_key'] is not None:
    if current_page['input_key'] == 'workload_scope':
        st.subheader("Workload Scope")
        col1, col2, col3 = st.columns(3)
        with col1:
            st.session_state.answers['workload_scope']['time_commitments'] = st.text_area(
                "Time Commitments:",
                value=st.session_state.answers['workload_scope'].get('time_commitments', ""),
                key="time_commitments",
                height=150
            )
        with col2:
            st.session_state.answers['workload_scope']['deadlines'] = st.text_area(
                "Deadlines:",
                value=st.session_state.answers['workload_scope'].get('deadlines', ""),
                key="deadlines",
                height=150
            )
        with col3:
            st.session_state.answers['workload_scope']['feature_prioritization'] = st.text_area(
                "Feature Prioritization:",
                value=st.session_state.answers['workload_scope'].get('feature_prioritization', ""),
                key="feature_prioritization",
                height=150
            )

    elif current_page['input_key'] == 'useful_assets':
        st.subheader("Useful Assets and Libraries")
        assets = st_tags(
            label='Enter Useful Assets and Libraries:',
            text='Press enter to add more',
            value=st.session_state.answers['useful_assets'].get('assets', []),
            suggestions=[],
            maxtags=5,
            key='useful_assets'
        )
        st.session_state.answers['useful_assets']['assets'] = assets

    elif current_page['input_key'] == 'pilot_evaluation':
        st.subheader("Pilot Evaluation")
        metrics = st_tags(
            label='Enter Metrics to Track:',
            text='Press enter to add more',
            value=st.session_state.answers['pilot_evaluation'].get('metrics', []),
            suggestions=[],
            maxtags=5,
            key='pilot_evaluation'
        )
        st.session_state.answers['pilot_evaluation']['metrics'] = metrics

# Generate PDF button (only on the last page)
if st.session_state.current_page == len(pages) - 1:
    if st.button("Generate and Download PDF", use_container_width=True):
        pdf = pdf_generator.generate_pdf(st.session_state)
        st.download_button(
            label="Download PDF",
            data=pdf,
            file_name="Pilot_Drafting.pdf",
            mime="application/pdf",
            use_container_width=True
        )

# Display progress
st.progress((st.session_state.current_page + 1) / len(pages))

st.divider()