Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 51 |
-
|
| 52 |
if st.button("Search"):
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
st.write(f"**Course Title:** {title}")
|
| 68 |
-
st.write(f"**Course Lessons:** {lessons}")
|
| 69 |
-
st.write("---")
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 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()
|