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(RAG based Application)" , 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. ✅ ASK questions like: 1)How can I identify the cues that trigger my unwanted habits? 2) Can I redesign my environment to make desired habits more visible and tempting? 3) What habit trackers or visual reminders could I use to stay on track? 4) What obstacles or friction points can I remove to simplify my desired habits? 5) Can I automate any steps in my routine to make it more effortless? 6) How can I track my progress and acknowledge my achievements to stay motivated? ❌ IT won't generate answer outside of the context such as? 1) Who is Sachin Tendulkar? 2) which is the most expensive car in the world? ") iface.launch()