Shroogawh24 commited on
Commit
624c95c
1 Parent(s): 554c5b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -2,22 +2,24 @@ import gradio as gr
2
  import os
3
  import openai
4
  import pandas as pd
5
- from langchain.embeddings import HuggingFaceBgeEmbeddings
6
  from langchain.vectorstores import FAISS
7
  from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
8
  from langchain.chains import LLMChain
9
  from langchain_core.output_parsers.string import StrOutputParser
10
  from langchain.chat_models import ChatOpenAI
 
11
 
12
  from sentence_transformers import SentenceTransformer
13
 
14
- embedding_function = SentenceTransformer("BAAI/bge-large-en-v1.5")
 
 
15
 
16
  # Set the OpenAI API key
17
  openai.api_key = os.getenv("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")
18
 
19
  # Load the FAISS index using LangChain's FAISS implementation
20
- db = FAISS.load_local("Faiss", embedding_function, allow_dangerous_deserialization=True)
21
  parser = StrOutputParser()
22
 
23
  # Load your data (e.g., a DataFrame)
@@ -25,7 +27,7 @@ df = pd.read_pickle('df_news (1).pkl')
25
 
26
  # Search function to retrieve relevant documents
27
  def search(query):
28
- query_embedding = embedding_function.embed_query(query).reshape(1, -1).astype('float32')
29
  D, I = db.similarity_search_with_score(query_embedding, k=10)
30
  results = []
31
  for idx in I[0]:
 
2
  import os
3
  import openai
4
  import pandas as pd
 
5
  from langchain.vectorstores import FAISS
6
  from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
7
  from langchain.chains import LLMChain
8
  from langchain_core.output_parsers.string import StrOutputParser
9
  from langchain.chat_models import ChatOpenAI
10
+ from langchain.embeddings.openai import OpenAIEmbeddings
11
 
12
  from sentence_transformers import SentenceTransformer
13
 
14
+ embeddings = OpenAIEmbeddings()
15
+
16
+ #embedding_function = SentenceTransformer("BAAI/bge-large-en-v1.5")
17
 
18
  # Set the OpenAI API key
19
  openai.api_key = os.getenv("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")
20
 
21
  # Load the FAISS index using LangChain's FAISS implementation
22
+ db = FAISS.load_local("Faiss", embeddings, allow_dangerous_deserialization=True)
23
  parser = StrOutputParser()
24
 
25
  # Load your data (e.g., a DataFrame)
 
27
 
28
  # Search function to retrieve relevant documents
29
  def search(query):
30
+ query_embedding = embeddings.embed_query(query).reshape(1, -1).astype('float32')
31
  D, I = db.similarity_search_with_score(query_embedding, k=10)
32
  results = []
33
  for idx in I[0]: