|
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=1) |
|
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." |
|
return ask_question(qa_system, prompt) |
|
|
|
|
|
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\nWelcome! Enter your area of interest to receive a course recommendation.") |
|
|
|
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) |
|
|