""" app.py Main script to run the Course Recommendation Chatbot using Gradio. """ import os import gradio as gr from document_loader import load_document from embeddings import process_documents_with_chroma from chatbot import create_chatbot, ask_question # Ensure your OpenAI API key is set in the environment variables. api_key = os.getenv("OPENAI_API_KEY") os.environ["OPENAI_API_KEY"] = api_key def main(query): """Main function to load document, create embeddings, and generate a response. Args: query (str): User input query for course recommendation. Returns: str: The chatbot's response. """ file_path = "Courses_Details.pdf" documents = load_document(file_path) vector_store = process_documents_with_chroma(documents) chatbot_system = create_chatbot(vector_store) prompt = f"Suggest me best course for {query} as an output in a well-written, elaborative, and structured format along with its link." return ask_question(chatbot_system, prompt) # Define the 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(""" # 🚀 Fast Course Recommendation Agent (Compact Version) Welcome to the **Compact Course Recommendation Chatbot**! This version is designed to provide lightning-fast course suggestions—**20x faster** than the full version—by working directly with a curated dataset of pre-scraped course information from Analytics Vidhya. ### How It Works The compact chatbot quickly searches through a stored database of pre-scraped courses, avoiding the need to scrape new data each time. This approach allows you to receive highly relevant course recommendations almost instantly. Just enter your area of interest (e.g., “data science” or “AI”), and let the compact chatbot do the rest! ### Key Features - **Blazing Fast Speed**: Get recommendations in seconds, thanks to the use of pre-scraped course data. - **Smart Recommendations**: The chatbot uses natural language processing to understand your query and recommend the best courses available. - **Direct Links**: Each recommendation includes a link so you can check out the course directly on Analytics Vidhya. ### How to Use Simply type in your topic of interest below, and the chatbot will provide a tailored course suggestion along with details such as the course curriculum, duration, instructor, and difficulty level. --- [Explore the Full Version](https://huggingface.co/spaces/raghuv-aditya/Course-Finder-AI-Large) if you’re looking for more customization options, including live scraping for the latest course updates. """) with gr.Group(): 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)