Spaces:
Runtime error
Runtime error
from flask import Flask, render_template, jsonify, request | |
from src.helper import download_hugging_face_embeddings | |
from langchain.vectorstores import Pinecone | |
import pinecone | |
from langchain.prompts import PromptTemplate | |
from langchain.llms import CTransformers | |
from langchain.chains import RetrievalQA | |
from dotenv import load_dotenv | |
from src.prompt import * | |
import os | |
from pinecone import Pinecone | |
from langchain_pinecone import PineconeVectorStore | |
from langchain.llms import Replicate | |
app = Flask(__name__) | |
load_dotenv() | |
#PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY') | |
#PINECONE_API_ENV = os.environ.get('PINECONE_API_ENV') | |
embeddings = download_hugging_face_embeddings() | |
#Initializing the Pinecone | |
index_name="clare" | |
#pc=Pinecone(api_key=PINECONE_API_KEY) | |
#index=pc.Index("clare") | |
#Loading the index | |
docsearch = PineconeVectorStore.from_existing_index(index_name, embeddings) | |
PROMPT=PromptTemplate(template=prompt_template, input_variables=["context", "question"]) | |
chain_type_kwargs={"prompt": PROMPT} | |
llm=Replicate(model="meta/meta-llama-3-8b") | |
qa=RetrievalQA.from_chain_type( | |
llm=llm, | |
chain_type="stuff", | |
retriever=docsearch.as_retriever(search_kwargs={'k': 2}), | |
return_source_documents=True, | |
chain_type_kwargs=chain_type_kwargs) | |
def index(): | |
return render_template('chat.html') | |
def chat(): | |
msg = request.form["msg"] | |
input = msg | |
print(input) | |
result=qa({"query": input}) | |
print("Response : ", result["result"]) | |
return str(result["result"]) | |
if __name__ == '__main__': | |
app.run(host="0.0.0.0", port= 8080, debug= True) |