raghuv-aditya's picture
Create app.py
ce728b2 verified
raw
history blame
2.17 kB
"""
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("""
# 🎓 Course Recommendation Chatbot
Welcome to the **Course Recommendation Chatbot**! This assistant can suggest the best courses based on your input, along with a well-structured description and course link.
Just enter the area you’re interested in (e.g., "machine learning") to receive a curated course recommendation!
""")
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)