Rauhan commited on
Commit
fc0f3cf
·
1 Parent(s): e7c07f7

Adding Files

Browse files
Files changed (2) hide show
  1. app.py +6 -10
  2. faiss_setup.py +1 -1
app.py CHANGED
@@ -8,6 +8,7 @@ import gradio as gr
8
  import os
9
 
10
  # initialising the locally saved vectorstore from artifacts
 
11
  model_name = "sentence-transformers/all-mpnet-base-v2"
12
  embeddings = HuggingFaceEmbeddings(model_name = model_name)
13
  vectorstore = FAISS.load_local("artifacts/FAISS-Vectorstore", embeddings)
@@ -16,27 +17,22 @@ vectorstore = FAISS.load_local("artifacts/FAISS-Vectorstore", embeddings)
16
  def generate_response(input_query):
17
  result = vectorstore.similarity_search_with_relevance_scores(input_query, k = 4)
18
  PROMPT_TEMPLATE = """
19
- Consider yourself to be a football expert who has been given the task to answer a question
20
- based on some of the content you are provided with along with their some relevance scores.
21
- Please restrict your knowledge to only the given content and do not add up anything on your own.
22
- Also make sure that if the top relevance score is less than 0.25, generate a response that you weren't able
23
- to find anything relevant from the knowledge base.
24
 
25
  Here's the question which you have been asked :
26
  {question}
27
 
28
  Here's the content you are provided with :
29
  {content}
30
-
31
- Here's the maximum relevance score :
32
- {score}
33
  """
34
 
35
  content = "\n-----\n".join([x[0].page_content for x in result])
36
- score = max([x[1] for x in result])
37
 
38
  prompt = PromptTemplate.from_template(PROMPT_TEMPLATE)
39
- prompt = prompt.format(question = input_query, content = content, score = score)
40
 
41
  llm = OpenAI(api_key = os.getenv("OPENAI_API_KEY"), temperature = 0.95)
42
  response = llm.predict(prompt).strip()
 
8
  import os
9
 
10
  # initialising the locally saved vectorstore from artifacts
11
+ player_names = pd.read_csv("artifacts/data.csv", encoding = "latin-1")["Name"].to_list()
12
  model_name = "sentence-transformers/all-mpnet-base-v2"
13
  embeddings = HuggingFaceEmbeddings(model_name = model_name)
14
  vectorstore = FAISS.load_local("artifacts/FAISS-Vectorstore", embeddings)
 
17
  def generate_response(input_query):
18
  result = vectorstore.similarity_search_with_relevance_scores(input_query, k = 4)
19
  PROMPT_TEMPLATE = """
20
+ Consider yourself to be a football expert who knows everything about 35 greatest football players of all time
21
+ according to "The Guardian", the names of the 35 players are : {names}.
22
+ Now you have been given the task to answer a question and have also been given some content which you can take help of
23
+ to generate a proper and much detailed response. You are completely free to elaborate and add more details if they are correct.
 
24
 
25
  Here's the question which you have been asked :
26
  {question}
27
 
28
  Here's the content you are provided with :
29
  {content}
 
 
 
30
  """
31
 
32
  content = "\n-----\n".join([x[0].page_content for x in result])
 
33
 
34
  prompt = PromptTemplate.from_template(PROMPT_TEMPLATE)
35
+ prompt = prompt.format(question = input_query, content = content, names = player_names)
36
 
37
  llm = OpenAI(api_key = os.getenv("OPENAI_API_KEY"), temperature = 0.95)
38
  response = llm.predict(prompt).strip()
faiss_setup.py CHANGED
@@ -7,7 +7,7 @@ import pandas as pd
7
  from tqdm import tqdm
8
 
9
  # reading names of the players in the data and displaying few of them
10
- players = pd.read_csv("artifacts\data.csv", encoding = "latin-1")["Name"].to_list()
11
 
12
  # extracting information about the players from their wikipedia pages
13
  content = ""
 
7
  from tqdm import tqdm
8
 
9
  # reading names of the players in the data and displaying few of them
10
+ players = pd.read_csv("artifacts/data.csv", encoding = "latin-1")["Name"].to_list()
11
 
12
  # extracting information about the players from their wikipedia pages
13
  content = ""