File size: 1,701 Bytes
8f087b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)

# 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\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)