Files changed (1) hide show
  1. app (1).py +67 -0
app (1).py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """app
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1MuuKKNek3EmP5A5aGk8ail0MmT7w10f9
8
+ """
9
+
10
+ !pip install -U langchain-community
11
+
12
+ !pip install langchain==0.3.0 llama-index==0.12.0 sentence-transformers faiss-cpu gradio
13
+
14
+ import pandas as pd
15
+
16
+ # Load your uploaded file
17
+ data = pd.read_csv('/content/course.csv')
18
+
19
+ # Combine TITLE, DESCRIPTION, and CURRICULUM for processing
20
+ docs = []
21
+ for _, row in data.iterrows():
22
+ content = f"{row['TITLE']}\n{row['DESCRIPTION']}\n{row['CURRICULUM']}"
23
+ docs.append({"content": content, "metadata": {"title": row['TITLE'], "url": row['URL']}})
24
+
25
+ from langchain.embeddings import HuggingFaceEmbeddings
26
+ from langchain.vectorstores import FAISS
27
+
28
+ # Create embeddings
29
+ embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
30
+ texts = [doc["content"] for doc in docs]
31
+ metadatas = [doc["metadata"] for doc in docs]
32
+
33
+ # Create FAISS Index
34
+ vectorstore = FAISS.from_texts(texts, embedding_model, metadatas=metadatas)
35
+
36
+ import os
37
+
38
+ # Replace 'YOUR_API_KEY' with your actual OpenAI API key
39
+ os.environ["OPENAI_API_KEY"] = "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"
40
+
41
+ from langchain.chains import RetrievalQA
42
+ from langchain.llms import OpenAI
43
+
44
+ retriever = vectorstore.as_retriever()
45
+ qa_chain = RetrievalQA.from_chain_type(llm=OpenAI(model_name="text-davinci-003"), retriever=retriever)
46
+
47
+ import gradio as gr
48
+
49
+ def smart_search(query):
50
+ results = retriever.get_relevant_documents(query)
51
+ response = ""
52
+ for result in results:
53
+ title = result.metadata.get("title", "No Title")
54
+ url = result.metadata.get("url", "No URL")
55
+ response += f"**{title}**\n[Link to Course]({url})\n\n"
56
+ return response.strip()
57
+
58
+ interface = gr.Interface(
59
+ fn=smart_search,
60
+ inputs="text",
61
+ outputs="markdown",
62
+ title="Smart Search for Analytics Vidhya Free Courses",
63
+ description="Enter a keyword or a query to find relevant free courses on Analytics Vidhya."
64
+ )
65
+
66
+ # Launch the Gradio app
67
+ interface.launch(share=True)