Spaces:
Sleeping
Sleeping
File size: 2,165 Bytes
ce728b2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
"""
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)
|