raghuv-aditya commited on
Commit
ce728b2
·
verified ·
1 Parent(s): 599840c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ app.py
3
+
4
+ Main script to run the Course Recommendation Chatbot using Gradio.
5
+ """
6
+
7
+ import os
8
+ import gradio as gr
9
+ from document_loader import load_document
10
+ from embeddings import process_documents_with_chroma
11
+ from chatbot import create_chatbot, ask_question
12
+
13
+ # Ensure your OpenAI API key is set in the environment variables.
14
+ api_key = os.getenv("OPENAI_API_KEY")
15
+ os.environ["OPENAI_API_KEY"] = api_key
16
+
17
+ def main(query):
18
+ """Main function to load document, create embeddings, and generate a response.
19
+
20
+ Args:
21
+ query (str): User input query for course recommendation.
22
+
23
+ Returns:
24
+ str: The chatbot's response.
25
+ """
26
+ file_path = "Courses_Details.pdf"
27
+ documents = load_document(file_path)
28
+ vector_store = process_documents_with_chroma(documents)
29
+ chatbot_system = create_chatbot(vector_store)
30
+
31
+ prompt = f"Suggest me best course for {query} as an output in a well-written, elaborative, and structured format along with its link."
32
+ return ask_question(chatbot_system, prompt)
33
+
34
+ # Define the Gradio interface
35
+ with gr.Blocks(css="""
36
+ .container {max-width: 800px; margin: auto; text-align: center;}
37
+ button {background-color: orange !important; color: white !important;}
38
+ #input_text, #output_text {margin-bottom: 20px;}
39
+ """) as demo:
40
+ gr.Markdown("""
41
+ # 🎓 Course Recommendation Chatbot
42
+ 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.
43
+
44
+ Just enter the area you’re interested in (e.g., "machine learning") to receive a curated course recommendation!
45
+ """)
46
+
47
+ with gr.Group():
48
+ input_text = gr.Textbox(label="Ask your question about courses", placeholder="e.g., Best courses for machine learning", elem_id="input_text")
49
+ output_text = gr.Textbox(label="Course Information", placeholder="Your course recommendation will appear here...", elem_id="output_text")
50
+
51
+ submit_button = gr.Button("Get Recommendation", elem_id="submit_button")
52
+
53
+ submit_button.click(fn=main, inputs=input_text, outputs=output_text)
54
+
55
+ demo.launch(share=True)