Spaces:
Sleeping
Sleeping
| import re | |
| from sklearn.metrics.pairwise import cosine_similarity | |
| def find_top_question(query, metadata, embeddings): | |
| query_embedding = model.encode(query, convert_to_tensor=True).cpu().numpy().reshape(1, -1) | |
| similarities = cosine_similarity(query_embedding, embeddings).flatten() | |
| top_index = similarities.argsort()[-1] | |
| top_result = metadata.iloc[top_index].copy() | |
| top_result['similarity_score'] = similarities[top_index] | |
| return top_result | |
| def generate_detailed_prompt(question_metadata): | |
| return ( | |
| f"Transform this LeetCode question into a real-world interview scenario.\n\n" | |
| f"**Company**: {question_metadata['company']}\n" | |
| f"**Question Name**: {question_metadata['questionName']}\n" | |
| f"**Difficulty Level**: {question_metadata['difficulty level']}\n" | |
| f"**Tags**: {question_metadata['Tags']}\n" | |
| f"**Content**: {question_metadata['Content']}\n" | |
| f"\nPlease create a real-world interview question based on this information. " | |
| f"Include sections for problem description, code template, sample input, and expected output." | |
| ) | |