File size: 8,787 Bytes
6911ee7 | 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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | import re
custom_css = """
<style>
/* Main colors and styling - adaptive to Streamlit's themes */
:root {
--primary: #A370F7; /* Light purple */
--primary-light: #BF9DF8; /* Lighter purple */
--secondary: #14B8A6; /* Kept teal as it works well with purple */
--danger: #FF4B4B;
--warning: #F7B32B;
--info: #4B9EFF; /* Blue for links */
--success: #14B8A6;
--header-color: #A370F7; /* Changed to purple */
--text-color: #FFFFFF;
}
/* Custom download button styling */
.stDownloadButton button {
background-color: #4B9EFF !important;
color: white !important;
border: none !important;
font-weight: 500 !important;
padding: 0.5rem 1rem !important;
}
.stDownloadButton button:hover {
background-color: var(--primary-light) !important;
color: white !important;
}
/* Download button container */
.download-btn-container {
text-align: center;
display: flex;
justify-content: center;
margin: 1rem auto;
}
/* Ensure full width */
.block-container {
max-width: 100% !important;
padding-left: 1rem !important;
padding-right: 1rem !important;
}
/* Page header styling */
.page-header {
padding: 0.8rem 0 0 0;
margin-bottom: 1.5rem;
}
.page-title {
font-size: 3.2rem;
font-weight: 700;
margin-bottom: 0.4rem;
padding-bottom: 0.5rem;
/* Color is now set inline */
}
.page-subtitle {
font-size: 1rem;
}
/* Section dividers */
.section-divider {
margin: 1.5rem 0;
height: 1px;
background-color: rgba(255, 255, 255, 0.1);
border: none;
}
/* Right sidebar styling */
.right-sidebar {
padding: 1rem 0;
}
/* Topic list sidebar styling */
.topic-list-sidebar {
margin-top: 1rem;
padding: 1rem;
background-color: transparent;
}
.topic-list-title {
font-size: 2rem;
font-weight: 600;
color: var(--header-color);
margin-bottom: 0.8rem;
}
.sidebar-topic-badge {
background-color: var(--primary);
color: var(--text-color);
padding: 0.3rem 0.6rem;
border-radius: 12px;
margin: 0.15rem;
display: inline-block;
font-weight: 500;
font-size: 0.75rem;
}
/* Metric cards with more vibrant colors */
.metric-container {
display: flex;
justify-content: space-between;
gap: 0.8rem;
margin-bottom: 1.5rem;
}
.metric-card {
background: var(--primary);
color: var(--text-color);
border-radius: 10px;
padding: 1.2rem;
flex: 1;
text-align: center;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}
.metric-value {
font-size: 2rem;
font-weight: 700;
margin-bottom: 0.4rem;
}
.metric-label {
font-size: 0.8rem;
opacity: 0.9;
letter-spacing: 0.4px;
text-transform: uppercase;
}
/* Section headers - line comes after text */
.section-header {
font-size: 1.4rem;
font-weight: 600;
color: var(--header-color);
margin: 1.5rem 0 0.8rem 0;
padding-bottom: 0.4rem;
border-bottom: 2px solid rgba(255, 75, 75, 0.3);
}
/* Sub-section headers */
.sub-header {
font-size: 1.1rem;
font-weight: 600;
color: var(--header-color);
margin: 1rem 0 0.6rem 0;
border-bottom: none;
}
/* Topic badges */
.topic-badge {
background-color: var(--primary);
color: var(--text-color);
padding: 0.4rem 0.8rem;
border-radius: 16px;
margin: 0.2rem;
display: inline-block;
font-weight: 500;
font-size: 0.8rem;
}
/* Resource links styling */
.resource-item a {
color: var(--info);
text-decoration: none;
transition: color 0.2s;
}
.resource-item a:hover {
color: var(--primary-light);
text-decoration: underline;
}
/* Transparent backgrounds for info boxes */
.stInfo {
background-color: rgba(75, 158, 255, 0.1) !important;
border-left: 3px solid var(--info) !important;
border-top: none !important;
border-right: none !important;
border-bottom: none !important;
}
.stSuccess {
background-color: rgba(20, 184, 166, 0.1) !important;
border-left: 3px solid var(--success) !important;
border-top: none !important;
border-right: none !important;
border-bottom: none !important;
}
/* Strengths and weakness cards */
.strength-card {
background-color: rgba(20, 184, 166, 0.1);
border-left: 3px solid var(--success);
padding: 0.8rem;
margin-bottom: 0.8rem;
border-radius: 4px;
font-size: 0.9rem;
}
.weakness-card {
background-color: rgba(255, 75, 75, 0.1);
border-left: 3px solid var(--danger);
padding: 0.8rem;
margin-bottom: 0.8rem;
border-radius: 4px;
font-size: 0.9rem;
}
/* Override Streamlit's default text size */
.stMarkdown {
font-size: 0.9rem !important;
}
/* Override streamlit headers */
h1 {
font-size: 2.2rem !important;
color: var(--header-color) !important;
}
h2 {
font-size: 1.4rem !important;
color: var(--header-color) !important;
}
h3 {
font-size: 1.1rem !important;
color: var(--header-color) !important;
}
h4, h5, h6 {
font-size: 1rem !important;
color: var(--header-color) !important;
}
</style>
"""
def clean_json_response(response_text):
"""Remove markdown code formatting and other unwanted characters from JSON responses"""
# Remove markdown code block syntax (```json and ```)
response_text = re.sub(r'^```json\s*', '', response_text)
response_text = re.sub(r'```json', '', response_text)
response_text = re.sub(r'\s*```$', '', response_text)
response_text = re.sub(r'```', '', response_text)
# Find the actual JSON content - from first { to last }
start_idx = response_text.find('{')
end_idx = response_text.rfind('}') + 1
if start_idx >= 0 and end_idx > start_idx:
return response_text[start_idx:end_idx]
return response_text
def generate_text_summary(summary_data, scores_list):
"""Generate a plain text version of the summary for downloading"""
# Calculate average score
avg_score = sum([sum(q_score) for q_score in scores_list]) / (len(scores_list) * 4) * 10
# Format topics as a comma-separated list
topics = summary_data.get("topics_covered", [])
topics_str = ", ".join(topics) if isinstance(topics, list) else str(topics)
# Build the text summary
text_summary = f"""INTERVIEW PERFORMANCE SUMMARY
==============================
OVERVIEW
------------------------------
Overall Score: {avg_score:.1f}/100
Questions Analyzed: {len(summary_data.get('comparison_table', []))}
Topics Covered: {topics_str}
PERFORMANCE OVERVIEW
------------------------------
{summary_data.get('trends', 'No trend data available')}
YOUR STRENGTHS
------------------------------
{summary_data.get('strengths', 'No strengths data available')}
AREAS FOR IMPROVEMENT
------------------------------
{summary_data.get('weaknesses', 'No weaknesses data available')}
QUESTION ANALYSIS
------------------------------
"""
# Add each question analysis
for i, item in enumerate(summary_data.get('comparison_table', [])):
text_summary += f"\nQ{i+1}: {item.get('question', 'Question')}\n"
text_summary += f"Key Differences: {item.get('differences', 'No comparison available')}\n"
text_summary += f"Strong Phrases: {item.get('strong_phrases', 'No notable phrases identified')}\n"
# Add resources
text_summary += "\nRECOMMENDED RESOURCES\n"
text_summary += "------------------------------\n"
resources = summary_data.get("resources", "No resources available")
if isinstance(resources, str):
if "\n" in resources:
resources_list = resources.split("\n")
for resource in resources_list:
if resource.strip(): # Skip empty lines
text_summary += f"- {resource}\n"
else:
text_summary += f"- {resources}\n"
return text_summary
|