gradio-demo / app.py
Vadhana's picture
Create app.py
0708f5c verified
import pandas as pd
import gradio as gr
# Load your CSV file
data = pd.read_csv('course.csv')
# Combine TITLE, DESCRIPTION, and CURRICULUM for processing
docs = [
{
"content": f"{row['TITLE']}\n{row['DESCRIPTION']}\n{row['CURRICULUM']}",
"metadata": {"title": row['TITLE'], "url": row['URL']}
}
for _, row in data.iterrows()
]
# Dummy retriever function for search (replace this with your actual search logic)
class Retriever:
def __init__(self, documents):
self.documents = documents
def get_relevant_documents(self, query):
# A simple search based on query matching the content (you can replace with more advanced logic)
results = []
for doc in self.documents:
if query.lower() in doc['content'].lower():
results.append(doc)
return results
# Initialize the retriever with the documents
retriever = Retriever(docs)
# Define the search function for Gradio interface
def smart_search(query):
results = retriever.get_relevant_documents(query)
response = ""
for result in results:
title = result['metadata'].get("title", "No Title")
url = result['metadata'].get("url", "No URL")
response += f"**{title}**\n[Link to Course]({url})\n\n"
return response.strip()
# Create the Gradio interface
interface = gr.Interface(
fn=smart_search,
inputs="text",
outputs="markdown",
title="Smart Search for Analytics Vidhya Free Courses",
description="Enter a keyword or a query to find relevant free courses on Analytics Vidhya."
)
# Launch the Gradio app
interface.launch(share=True)