File size: 3,284 Bytes
0300fda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pickle
import pandas as pd
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity

# Load model and data
with open("course_emb.pkl", "rb") as f:
    course_emb = pickle.load(f)

df = pd.read_excel("analytics_vidhya_courses_Final.xlsx")
model = SentenceTransformer('all-MiniLM-L6-v2')

def search_courses(query, top_n=5):
    if not query.strip():
        return "Please enter a search query."
    
    query_embedding = model.encode([query])
    similarities = cosine_similarity(query_embedding, course_emb)
    top_n_idx = similarities[0].argsort()[-top_n:][::-1]
    
    results = []
    for idx in top_n_idx:
        course = df.iloc[idx]
        results.append({
            "title": course["Course Title"],
            "description": course["Course Description"],
            "similarity": float(similarities[0][idx])
        })
    return results

def gradio_interface(query):
    results = search_courses(query)
    if isinstance(results, str):
        return results
    
    # Format results as HTML with updated styling
    html_output = "<div style='font-family: Inter, sans-serif;'>"
    
    for i, course in enumerate(results, 1):
        relevance = int(course['similarity'] * 100)
        html_output += f"""
        <div style='background: #f8f9fa; padding: 20px; margin: 15px 0; border-radius: 12px; box-shadow: 0 2px 6px rgba(0,0,0,0.05);'>
            <h3 style='color: #1a237e; margin: 0 0 12px 0; font-weight: 600;'>#{i}. {course['title']}</h3>
            <div style='color: #3949ab; font-size: 0.9em; margin-bottom: 10px; font-weight: 500;'>Match Score: {relevance}%</div>
            <p style='color: #424242; margin: 0; line-height: 1.6;'>{course['description']}</p>
        </div>
        """
    
    html_output += "</div>"
    return html_output

# Create Gradio interface with improved styling
css = """
.gradio-container {
    font-family: 'Inter', sans-serif;
}
.gradio-button {
    background: linear-gradient(135deg, #3949ab, #1a237e) !important;
}
.gradio-button:hover {
    background: linear-gradient(135deg, #1a237e, #3949ab) !important;
}
"""

with gr.Blocks(css=css, theme="soft") as iface:
    gr.Markdown(
        """
        # 😻 Smart Learning Pathfinder
        Unlock your learning potential with AI-powered course recommendations tailored just for you!
        """
    )
    
    with gr.Row():
        query_input = gr.Textbox(
            label="What would you like to master?",
            placeholder="Tell us your learning interests (e.g., 'AI fundamentals' or 'data science for beginners')",
            scale=4
        )
    
    with gr.Row():
        search_button = gr.Button("✨ Discover Courses", variant="primary")
    
    with gr.Row():
        output = gr.HTML(label="Personalized Recommendations")
    
    search_button.click(
        fn=gradio_interface,
        inputs=query_input,
        outputs=output,
    )
    
    gr.Markdown(
        """
        ### 💡 Optimization Tips:
        - Share your current knowledge level
        - Mention specific skills you want to develop
        - Include your learning preferences
        - Specify your target outcomes
        """
    )

# Launch the interface
iface.launch(share=True)