Spaces:
Sleeping
Sleeping
Upload app.py
Browse filesUploading Final Project
app.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 6 |
+
|
| 7 |
+
# Load model and data
|
| 8 |
+
with open("course_emb.pkl", "rb") as f:
|
| 9 |
+
course_emb = pickle.load(f)
|
| 10 |
+
|
| 11 |
+
df = pd.read_excel("analytics_vidhya_courses_Final.xlsx")
|
| 12 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 13 |
+
|
| 14 |
+
def search_courses(query, top_n=5):
|
| 15 |
+
if not query.strip():
|
| 16 |
+
return "Please enter a search query."
|
| 17 |
+
|
| 18 |
+
query_embedding = model.encode([query])
|
| 19 |
+
similarities = cosine_similarity(query_embedding, course_emb)
|
| 20 |
+
top_n_idx = similarities[0].argsort()[-top_n:][::-1]
|
| 21 |
+
|
| 22 |
+
results = []
|
| 23 |
+
for idx in top_n_idx:
|
| 24 |
+
course = df.iloc[idx]
|
| 25 |
+
results.append({
|
| 26 |
+
"title": course["Course Title"],
|
| 27 |
+
"description": course["Course Description"],
|
| 28 |
+
"similarity": float(similarities[0][idx])
|
| 29 |
+
})
|
| 30 |
+
return results
|
| 31 |
+
|
| 32 |
+
def gradio_interface(query):
|
| 33 |
+
results = search_courses(query)
|
| 34 |
+
if isinstance(results, str):
|
| 35 |
+
return results
|
| 36 |
+
|
| 37 |
+
# Format results as HTML for better presentation
|
| 38 |
+
html_output = "<div style='font-family: Arial, sans-serif;'>"
|
| 39 |
+
|
| 40 |
+
for i, course in enumerate(results, 1):
|
| 41 |
+
relevance = int(course['similarity'] * 100)
|
| 42 |
+
html_output += f"""
|
| 43 |
+
<div style='background: white; padding: 15px; margin: 10px 0; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);'>
|
| 44 |
+
<h3 style='color: #2c3e50; margin: 0 0 10px 0;'>#{i}. {course['title']}</h3>
|
| 45 |
+
<div style='color: #7f8c8d; font-size: 0.9em; margin-bottom: 8px;'>Relevance: {relevance}%</div>
|
| 46 |
+
<p style='color: #34495e; margin: 0; line-height: 1.5;'>{course['description']}</p>
|
| 47 |
+
</div>
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
html_output += "</div>"
|
| 51 |
+
return html_output
|
| 52 |
+
|
| 53 |
+
# Create Gradio interface with improved styling
|
| 54 |
+
css = """
|
| 55 |
+
.gradio-container {
|
| 56 |
+
font-family: 'Arial', sans-serif;
|
| 57 |
+
}
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
with gr.Blocks(css=css) as iface:
|
| 61 |
+
gr.Markdown(
|
| 62 |
+
"""
|
| 63 |
+
# 🎓 EduPath Explorer
|
| 64 |
+
Discover your ideal learning path! Simply describe what you want to learn, and let our AI find the perfect courses for you.
|
| 65 |
+
"""
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
with gr.Row():
|
| 69 |
+
query_input = gr.Textbox(
|
| 70 |
+
label="Describe Your Learning Goals",
|
| 71 |
+
placeholder="e.g., 'data visualization fundamentals' or 'deep learning with practical projects'",
|
| 72 |
+
scale=4
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
with gr.Row():
|
| 76 |
+
search_button = gr.Button("🎯 Find My Courses", variant="primary")
|
| 77 |
+
|
| 78 |
+
with gr.Row():
|
| 79 |
+
output = gr.HTML(label="Recommended Courses")
|
| 80 |
+
|
| 81 |
+
search_button.click(
|
| 82 |
+
fn=gradio_interface,
|
| 83 |
+
inputs=query_input,
|
| 84 |
+
outputs=output,
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
gr.Markdown(
|
| 88 |
+
"""
|
| 89 |
+
### 💡 Search Tips:
|
| 90 |
+
- Mention your current expertise level
|
| 91 |
+
- Include specific technologies or tools
|
| 92 |
+
- Describe your end goals
|
| 93 |
+
- Add preferred learning style (hands-on, theoretical, etc.)
|
| 94 |
+
"""
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
# Launch the interface
|
| 98 |
+
iface.launch(share=True)
|