MindStride / app.py
devmit's picture
dsdf
f60206e
raw
history blame
No virus
2 kB
import gradio as gr
import os
import pinecone
from dotenv import load_dotenv
from langchain.chains import RetrievalQA
from langchain.vectorstores import Pinecone
from langchain.chat_models import ChatOpenAI
from langchain.embeddings import HuggingFaceInferenceAPIEmbeddings
# load_dotenv()
# APIS
OPENAI_API_KEY=os.environ["OPENAI_API_KEY"]
PINECONE_API_KEY=os.environ["PINECONE_API_KEY"]
HF_API=os.environ["HF_API"]
def model(query):
pinecone.init(
api_key=PINECONE_API_KEY, # find at app.pinecone.io
environment='gcp-starter', # next to api key in console
)
embeddings = HuggingFaceInferenceAPIEmbeddings(api_key=HF_API ,model_name="llmrails/ember-v1")
vectorstore = Pinecone.from_existing_index('legal-gpt', embeddings)
docs = vectorstore.similarity_search(query,k=5)
llm = ChatOpenAI(model_name="gpt-3.5-turbo",temperature=0.76, max_tokens=100, model_kwargs={"seed":235, "top_p":0.01})
chain = RetrievalQA.from_chain_type(llm, chain_type="stuff", retriever=vectorstore.as_retriever())
answer=chain.run({"query": query + "you are a therapist who help people with personal development and self improvement"+ "You can only make conversations related to the provided context. If a response cannot be formed strictly using the context, politely say you don’t have knowledge about that topic."+"[strictly within 75 words]"})
return answer
def greet(query):
return model(query)
iface = gr.Interface(fn=greet, inputs="text", outputs="text", title="MindStride" , description=" MindStride could imply the idea of taking intentional steps or strides toward better mental health, personal growth, or self-improvement. The term Mind refers to the mental aspect, encompassing thoughts, emotions, and mindfulness. Stride typically denotes a purposeful, confident step or movement forward. Therefore, MindStride might signify a deliberate journey or progress in enhancing mental well-being, personal development, or self-discovery.")
iface.launch()