pracheeeeez commited on
Commit
b27a6fd
·
verified ·
1 Parent(s): 50b12d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -25
app.py CHANGED
@@ -4,6 +4,7 @@ from langchain.embeddings import HuggingFaceEmbeddings
4
  from langchain.schema import Document
5
  from transformers import pipeline
6
  import pickle
 
7
 
8
  def load_faiss_index(index_file="faiss_course_index.pkl"):
9
  with open(index_file, "rb") as f:
@@ -46,34 +47,37 @@ def search_and_answer(query, index_file="faiss_course_index.pkl"):
46
  return response
47
 
48
  def main():
49
- st.title("Course Search WebApp")
50
- query = st.text_input("Enter your query:")
51
-
52
  if st.button("Search"):
53
- response = search_and_answer(query, index_file = "faiss_course_index.pkl")
54
- if response == "No relevant courses found.":
55
- st.write(response)
56
- else :
57
- st.write(response)
58
- '''
59
- retriever = get_faiss_retriever("faiss_course_index.pkl")
60
- retrieved_docs = retriever.invoke(query)
61
- count = len(retrieved_docs)
62
- st.write(f"Related Courses:{count}")
 
 
 
 
 
 
 
 
 
 
63
 
64
- for doc in retrieved_docs:
65
- title = doc.metadata.get('title', 'No Title')
66
- lessons = doc.metadata.get('lessons', 'No lessons listed')
67
- st.write(f"**Course Title:** {title}")
68
- st.write(f"**Course Lessons:** {lessons}")
69
- st.write("---")
70
 
71
- # Generate summary
72
- context = retrieved_docs[0].page_content
73
- summary = get_answer_from_t5(query, context)
74
- st.write("**Summary:**")
75
- st.write(summary)
76
- '''
77
 
78
  if __name__ == "__main__":
79
  main()
 
4
  from langchain.schema import Document
5
  from transformers import pipeline
6
  import pickle
7
+ import time
8
 
9
  def load_faiss_index(index_file="faiss_course_index.pkl"):
10
  with open(index_file, "rb") as f:
 
47
  return response
48
 
49
  def main():
50
+ st.title("📚 Course Search WebApp")
51
+ st.markdown("Find the best courses tailored to your needs.")
52
+ query = st.text_input("🔍 Enter your query:")
53
  if st.button("Search"):
54
+ with st.spinner("Fetching results..."):
55
+ start_time = time.time()
56
+ response = search_and_answer(query, index_file="faiss_course_index.pkl")
57
+ if response == "No relevant courses found.":
58
+ st.warning(response)
59
+ else:
60
+ st.success("Results fetched successfully!")
61
+
62
+ # Display the formatted response
63
+ sections = response.split("\n\n")
64
+ st.markdown("### **Related Courses:**")
65
+ for section in sections[:-1]: # Exclude summary section
66
+ if section.strip():
67
+ st.markdown(section)
68
+ st.write("---")
69
+
70
+ # Display summary
71
+ summary = sections[-1].replace("Summary:", "").strip()
72
+ st.subheader("📝 Summary:")
73
+ st.info(summary)
74
 
75
+ # Log time taken
76
+ end_time = time.time()
77
+ st.markdown(f"⏱ **Time Taken:** {end_time - start_time:.2f} seconds")
 
 
 
78
 
79
+ st.markdown("---")
80
+ st.markdown("Developed with ❤️ by [Your Name](https://your-link.com)")
 
 
 
 
81
 
82
  if __name__ == "__main__":
83
  main()