File size: 6,339 Bytes
43305fa
 
6ff5358
43305fa
 
 
6ff5358
195b6e9
 
 
6ff5358
195b6e9
 
43305fa
a4b0377
195b6e9
 
a4b0377
 
 
 
 
 
 
 
 
 
195b6e9
 
a4b0377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195b6e9
 
43305fa
6ff5358
43305fa
 
 
 
 
6ff5358
195b6e9
43305fa
6ff5358
 
43305fa
 
 
 
 
 
6ff5358
43305fa
6ff5358
 
 
 
 
 
43305fa
6ff5358
 
 
 
 
 
 
 
 
43305fa
6ff5358
 
 
 
 
 
43305fa
6ff5358
 
 
 
43305fa
6ff5358
 
 
43305fa
 
6ff5358
 
 
43305fa
6ff5358
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import spacy
from spacy.cli import download
import numpy as np
from numpy.linalg import norm

# Download spaCy model if not already installed
try:
    nlp = spacy.load("en_core_web_md")
except OSError:
    st.warning("Downloading the spaCy model. Please wait...")
    download("en_core_web_md")
    nlp = spacy.load("en_core_web_md")

# Step 3: Hardcode the FAQ data
faqs = {
    'Admissions': [
        {'question': 'What is the process for admission into Saras AI Institute?', 
         'answer': 'The admission process at Saras AI Institute typically involves submitting the online application form along with necessary details, followed by a quick pre-enrollment assessment to evaluate your candidature based on your personal traits and basic communication skills in English.'},
        {'question': 'Is there an application fee for applying to Saras AI Institute?', 
         'answer': 'There is no application fee for applying to any program at Saras.'},
        {'question': 'What is pre-enrollment assessment test? How do I prepare for it?', 
         'answer': 'It is a fully online assessment which takes less than 15 minutes. It evaluates your personal traits and basic English communication skills. No specific preparation is required.'},
        {'question': 'Are there any specific requirements or prerequisites for admission into the programs?', 
         'answer': 'You need basic mathematical proficiency and English communication skills to join the programs. Math scores from high school or beyond can demonstrate your readiness.'},
        {'question': 'When is the deadline for submitting the application?', 
         'answer': 'The deadline for submitting applications is 5th August 2024.'}
    ],
    'Curriculum and Faculty': [
        {'question': 'What is the curriculum like at Saras AI Institute?', 
         'answer': 'The curriculum imparts both technical and human skills, preparing students for roles such as AI/ML Engineer, Data Scientist, and Gen AI Engineer.'},
        {'question': 'What does the program structure look like, and how is the curriculum delivered?', 
         'answer': 'Each year is divided into 5 semesters of 8 weeks. The program includes a mix of recorded and live sessions.'},
        {'question': 'Do you also conduct LIVE sessions?', 
         'answer': 'Yes, live sessions provide interactive learning and Q&A opportunities with instructors.'},
        {'question': 'Can I transfer credits earned at other universities to Saras AI Institute?', 
         'answer': 'Yes, relevant credits can be transferred after evaluation.'}
    ],
    'Accreditation & Recognition': [
        {'question': 'Is Saras AI Institute accredited?', 
         'answer': 'Not yet. This is our first enrollment cycle, and accreditation takes time.'},
        {'question': 'Are the degree programs recognized by the government?', 
         'answer': 'Yes, we are a state-approved degree-granting institute based in the U.S.'}
    ],
    'Career Services': [
        {'question': 'Does Saras AI Institute offer employment support?', 
         'answer': 'Yes, we provide comprehensive employment support, including job placement services and interview preparation.'},
        {'question': ' Does the university offer internship placement assistance?', 
         'answer': 'Yes, we assist students in finding internships through employer connections.'}
    ],
    'Tuition fee and Scholarships': [
        {'question': 'Does Saras AI Institute offer any scholarships for students?', 
         'answer': 'Yes, scholarships are available based on academic merit and financial need.'},
        {'question': 'What are the tuition fees for your courses?', 
         'answer': "You can find detailed information on the 'Programs' page on our website."}
    ]
}

# Precompute vectors for FAQ questions
faq_docs = []
for category, faq_list in faqs.items():
    for faq in faq_list:
        question = faq['question']
        answer = faq['answer']
        faq_vector = nlp(question).vector
        faq_docs.append((question, answer, faq_vector))

def find_most_relevant_faq(query, faq_docs):
    """Find the most relevant FAQs based on cosine similarity."""
    query_vector = nlp(query).vector
    similarities = [
        (question, answer, np.dot(query_vector, faq_vector) / (norm(query_vector) * norm(faq_vector)))
        for question, answer, faq_vector in faq_docs
    ]
    similarities = sorted(similarities, key=lambda x: x[2], reverse=True)
    return similarities[:3]

# Enhanced Streamlit UI
st.set_page_config(
    page_title="Smart FAQ Search - SARAS AI Institute",
    page_icon="πŸ“š",
    layout="wide"
)

# Sidebar for Navigation
with st.sidebar:
    st.image("https://via.placeholder.com/150", caption="Saras AI Institute")
    st.title("FAQ Search")
    st.markdown("### Navigate:")
    st.markdown("1. **Ask a Question**")
    st.markdown("2. **Explore FAQs by Category**")
    st.markdown("---")
    st.write("πŸ“§ Contact us: [email protected]")

# Main Header Section
st.title("πŸ“– Smart FAQ Search")
st.markdown(
    "<h4 style='color: #4CAF50;'>Find answers to your questions instantly!</h4>", 
    unsafe_allow_html=True
)

# Input section with a placeholder
query = st.text_input("πŸ” Ask a question:", placeholder="E.g., What is the admission process?")

# Display FAQs based on user query
if query:
    st.markdown("---")
    st.markdown("### πŸ”Ž Top Relevant FAQs:")
    top_faqs = find_most_relevant_faq(query, faq_docs)

    for i, (question, answer, score) in enumerate(top_faqs, 1):
        with st.expander(f"**{i}. {question}**"):
            st.write(answer)
            st.caption(f"Similarity Score: {score:.2f}")
else:
    st.info("Enter a question above to find the most relevant FAQs.")

# Add an Explore Section with FAQ Categories
st.markdown("---")
st.markdown("### πŸ“‚ Explore FAQs by Category")

for category, faq_list in faqs.items():
    with st.expander(f"**{category}**"):
        for faq in faq_list:
            st.write(f"**Q:** {faq['question']}")
            st.write(f"**A:** {faq['answer']}")

# Footer Section
st.markdown("---")
st.markdown(
    "<div style='text-align: center;'>"
    "πŸ’¬ Need more help? Contact us at <a href='mailto:[email protected]'>[email protected]</a>."
    "</div>",
    unsafe_allow_html=True
)