raghuv-aditya commited on
Commit
8f087b7
·
verified ·
1 Parent(s): 4379680

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from scraper import scrape_courses_json
3
+ from text_processing import generate_text
4
+ from embedding_storage import process_safety_with_chroma
5
+ from qa_chatbot import create_chatbot, ask_question
6
+ from config import BASE_URL
7
+
8
+ def main(query):
9
+ """
10
+ Main function to scrape courses, process embeddings, and retrieve answers.
11
+
12
+ Args:
13
+ query (str): User's query for course recommendation.
14
+
15
+ Returns:
16
+ str: Response from the chatbot with a recommended course.
17
+ """
18
+ courses_data = scrape_courses_json(BASE_URL, num_pages=1)
19
+ course_text = generate_text(courses_data)
20
+ vector_store = process_safety_with_chroma(course_text)
21
+ qa_system = create_chatbot(vector_store)
22
+
23
+ prompt = "Suggest me the best course for " + query + " in a structured format with a link."
24
+ return ask_question(qa_system, prompt)
25
+
26
+ # Gradio interface
27
+ with gr.Blocks(css="""
28
+ .container {max-width: 800px; margin: auto; text-align: center;}
29
+ button {background-color: orange !important; color: white !important;}
30
+ #input_text, #output_text {margin-bottom: 20px;}
31
+ """) as demo:
32
+ gr.Markdown("# 🎓 Course Recommendation Chatbot\nWelcome! Enter your area of interest to receive a course recommendation.")
33
+
34
+ input_text = gr.Textbox(label="Ask your question about courses", placeholder="e.g., Best courses for machine learning", elem_id="input_text")
35
+ output_text = gr.Textbox(label="Course Information", placeholder="Your course recommendation will appear here...", elem_id="output_text")
36
+ submit_button = gr.Button("Get Recommendation", elem_id="submit_button")
37
+
38
+ submit_button.click(fn=main, inputs=input_text, outputs=output_text)
39
+
40
+ demo.launch(share=True)