raghuv-aditya's picture
Update app.py
2ac3f7b verified
import gradio as gr
from scraper import scrape_courses_json
from text_processing import generate_text
from embedding_storage import process_safety_with_chroma
from qa_chatbot import create_chatbot, ask_question
from config import BASE_URL
def main(query):
"""
Main function to scrape courses, process embeddings, and retrieve answers.
Args:
query (str): User's query for course recommendation.
Returns:
str: Response from the chatbot with a recommended course.
"""
courses_data = scrape_courses_json(BASE_URL, num_pages=8)
course_text = generate_text(courses_data)
vector_store = process_safety_with_chroma(course_text)
qa_system = create_chatbot(vector_store)
prompt = "Suggest me the best course for " + query + " in a structured format with a link from the content provided only."
return ask_question(qa_system, prompt)
# Gradio interface
with gr.Blocks(css="""
.container {max-width: 800px; margin: auto; text-align: center;}
button {background-color: orange !important; color: white !important;}
#input_text, #output_text {margin-bottom: 20px;}
""") as demo:
gr.Markdown("""
# 🎓 Course Recommendation Agent
Welcome to the **Course Recommendation Chatbot**! This tool was built to provide personalized course suggestions based on your unique interests and learning goals from Analytics Vidhya. Here’s a quick look at what makes this tool effective and how it was created:
### How it Works
The chatbot uses advanced language models and a robust information retrieval setup to recommend courses from **Analytics Vidhya’s free courses**. When you ask about a topic (like "machine learning"), the tool:
1. **Scrapes Course Data**: It collects data directly from the course pages, extracting titles, descriptions, curriculum highlights, target audience, and other course details.
2. **Processes Course Information**: Using language models, each course’s text is broken down into small, searchable chunks that allow the chatbot to find the most relevant content quickly.
3. **Searches and Ranks Results**: A vector search database, powered by **ChromaDB** with OpenAI’s embeddings, stores course information for efficient retrieval. When you ask a question, the system ranks the top courses by relevance.
4. **Presents the Best Match**: Finally, it presents the course recommendation in a structured format, including a description, curriculum highlights, duration, level, instructor info, and a link for easy access.
### Key Features
- **Instant Recommendations**: Get real-time, customized course recommendations based on your interests.
- **Detailed Information**: Each recommendation includes essential details, such as the course curriculum, target audience, and skill level.
- **User-Friendly Interface**: Powered by **Gradio**, the chatbot is designed to be intuitive and interactive.
This course recommendation chatbot combines **web scraping, language processing**, and **retrieval-augmented generation** techniques to deliver high-quality course recommendations. Just type in the area you’re interested in, and get a course that’s right for you!
For those who prefer even faster results, there’s a **compact version** of this chatbot that works on pre-scraped course data and delivers recommendations **20x faster**! [Try the compact version here](https://huggingface.co/spaces/raghuv-aditya/Course-Finder-AI).
> **Bonus Tip**: Check out the logs to see the full list of courses scraped just for you – consider it a backstage pass to your learning options! 😎
""")
input_text = gr.Textbox(label="Ask your question about courses", placeholder="e.g., Best courses for machine learning", elem_id="input_text")
output_text = gr.Textbox(label="Course Information", placeholder="Your course recommendation will appear here...", elem_id="output_text")
submit_button = gr.Button("Get Recommendation", elem_id="submit_button")
submit_button.click(fn=main, inputs=input_text, outputs=output_text)
demo.launch(share=True)