import re custom_css = """ """ 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