Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,9 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
##########
|
|
|
|
|
|
|
|
|
|
| 5 |
from langchain.vectorstores import Chroma
|
| 6 |
from langchain.embeddings import OpenAIEmbeddings
|
| 7 |
|
|
@@ -13,6 +16,18 @@ from langchain.embeddings import HuggingFaceEmbeddings
|
|
| 13 |
|
| 14 |
import gradio as gr
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
"""
|
| 17 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 18 |
"""
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
##########
|
| 5 |
+
import os
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
from langchain.vectorstores import Chroma
|
| 9 |
from langchain.embeddings import OpenAIEmbeddings
|
| 10 |
|
|
|
|
| 16 |
|
| 17 |
import gradio as gr
|
| 18 |
|
| 19 |
+
MODEL = "gpt-4o-mini"
|
| 20 |
+
db_name = "vector_db"
|
| 21 |
+
|
| 22 |
+
load_dotenv()
|
| 23 |
+
os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')
|
| 24 |
+
|
| 25 |
+
vectorstore = Chroma(persist_directory=db_name, embedding_function=OpenAIEmbeddings())
|
| 26 |
+
llm = ChatOpenAI(temperature=0.7, model_name=MODEL)
|
| 27 |
+
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 28 |
+
retriever = vectorstore.as_retriever()
|
| 29 |
+
conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=retriever, memory=memory)
|
| 30 |
+
|
| 31 |
"""
|
| 32 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 33 |
"""
|