Vadhana commited on
Commit
0708f5c
·
verified ·
1 Parent(s): f54cfd7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+
4
+ # Load your CSV file
5
+ data = pd.read_csv('course.csv')
6
+
7
+ # Combine TITLE, DESCRIPTION, and CURRICULUM for processing
8
+ docs = [
9
+ {
10
+ "content": f"{row['TITLE']}\n{row['DESCRIPTION']}\n{row['CURRICULUM']}",
11
+ "metadata": {"title": row['TITLE'], "url": row['URL']}
12
+ }
13
+ for _, row in data.iterrows()
14
+ ]
15
+
16
+ # Dummy retriever function for search (replace this with your actual search logic)
17
+ class Retriever:
18
+ def __init__(self, documents):
19
+ self.documents = documents
20
+
21
+ def get_relevant_documents(self, query):
22
+ # A simple search based on query matching the content (you can replace with more advanced logic)
23
+ results = []
24
+ for doc in self.documents:
25
+ if query.lower() in doc['content'].lower():
26
+ results.append(doc)
27
+ return results
28
+
29
+ # Initialize the retriever with the documents
30
+ retriever = Retriever(docs)
31
+
32
+ # Define the search function for Gradio interface
33
+ def smart_search(query):
34
+ results = retriever.get_relevant_documents(query)
35
+ response = ""
36
+ for result in results:
37
+ title = result['metadata'].get("title", "No Title")
38
+ url = result['metadata'].get("url", "No URL")
39
+ response += f"**{title}**\n[Link to Course]({url})\n\n"
40
+ return response.strip()
41
+
42
+ # Create the Gradio interface
43
+ interface = gr.Interface(
44
+ fn=smart_search,
45
+ inputs="text",
46
+ outputs="markdown",
47
+ title="Smart Search for Analytics Vidhya Free Courses",
48
+ description="Enter a keyword or a query to find relevant free courses on Analytics Vidhya."
49
+ )
50
+
51
+ # Launch the Gradio app
52
+ interface.launch(share=True)