File size: 2,001 Bytes
ab2bd9d
bd9c957
 
 
 
 
 
 
ab2bd9d
bd9c957
 
497bc13
bd9c957
 
4003b6d
 
 
 
bd9c957
 
 
 
 
497bc13
bd9c957
 
497bc13
 
bd9c957
 
 
 
 
 
 
 
 
 
 
ab2bd9d
f60206e
ab2bd9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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()