SagayaAbinesh commited on
Commit
e2979c7
1 Parent(s): baa905e

Upload 8 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ data/Encyclopedia[[:space:]]of[[:space:]]Bodybuilding_[[:space:]]The[[:space:]]Complete[[:space:]]A-Z[[:space:]]Book[[:space:]]on[[:space:]]Muscle[[:space:]]Building[[:space:]]([[:space:]]PDFDrive[[:space:]])_compressed.pdf filter=lfs diff=lfs merge=lfs -text
37
+ gym_vector_db/index.faiss filter=lfs diff=lfs merge=lfs -text
WE_GO_JIM.png ADDED
data/Encyclopedia of Bodybuilding_ The Complete A-Z Book on Muscle Building ( PDFDrive )_compressed.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0501fc057d1216c4ef74ccba202e925238d422fd39af91c073e8422ecf101271
3
+ size 35789889
gemini_gym_app.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.vectorstores import FAISS
2
+ from langchain_community.embeddings import HuggingFaceEmbeddings
3
+ from langchain.prompts import PromptTemplate
4
+ import os
5
+ from langchain.memory import ConversationBufferWindowMemory
6
+ from langchain.chains import ConversationalRetrievalChain
7
+ import time
8
+ from langchain_google_genai import ChatGoogleGenerativeAI
9
+ import streamlit as st
10
+
11
+ st.set_page_config(page_title="GymGPT")
12
+ col1, col2, col3 = st.columns([1,2,1])
13
+ with col2:
14
+ st.title("GymGPT 🦾")
15
+
16
+
17
+ st.sidebar.title("Welcome to GymGPT")
18
+ st.sidebar.image(r"C:\Users\Sagaya Abinesh\Documents\gymgpt\WE_GO_JIM.png", width=275)
19
+ st.sidebar.title("Shoot your gym-related questions")
20
+ st.markdown(
21
+ """
22
+ <style>
23
+ div.stButton > button:first-child {
24
+ background-color: #ffd0d0;
25
+ }
26
+
27
+ div.stButton > button:active {
28
+ background-color: #ff6262;
29
+ }
30
+
31
+ .st-emotion-cache-6qob1r {
32
+ position: relative;
33
+ height: 100%;
34
+ width: 100%;
35
+ background-color: black;
36
+ overflow: overlay;
37
+ }
38
+
39
+ div[data-testid="stStatusWidget"] div button {
40
+ display: none;
41
+ }
42
+
43
+ .reportview-container {
44
+ margin-top: -2em;
45
+ }
46
+ #MainMenu {visibility: hidden;}
47
+ .stDeployButton {display:none;}
48
+ footer {visibility: hidden;}
49
+ #stDecoration {display:none;}
50
+ button[title="View fullscreen"]{
51
+ visibility: hidden;}
52
+ </style>
53
+ """,
54
+ unsafe_allow_html=True,
55
+ )
56
+
57
+ def reset_conversation():
58
+ st.session_state.messages = []
59
+ st.session_state.memory.clear()
60
+
61
+ if "messages" not in st.session_state:
62
+ st.session_state.messages = []
63
+
64
+ if "memory" not in st.session_state:
65
+ st.session_state.memory = ConversationBufferWindowMemory(k=2, memory_key="chat_history",return_messages=True)
66
+
67
+ embeddings = HuggingFaceEmbeddings(model_name="nomic-ai/nomic-embed-text-v1-ablated", model_kwargs={"trust_remote_code": True})
68
+ db = FAISS.load_local(r"C:\Users\Sagaya Abinesh\Documents\gymgpt\gym_vector_db", embeddings)
69
+ db_retriever = db.as_retriever(search_type="similarity",search_kwargs={"k": 4})
70
+
71
+ prompt_template = """<s>[INST]This is a chat template and you are the gym trainer, your primary objective is to provide accurate and concise information related to gym, workout, bodybuilding based on the user's questions. Do not generate your own questions and answers. You will adhere strictly to the instructions provided, offering relevant context from the knowledge base while avoiding unnecessary details. Your responses will be brief, to the point, and in compliance with the established format. If a question falls outside the given context, rely on your own knowledge base to generate an appropriate response. You will prioritize the user's query and refrain from posing additional questions and do not repeat the prompt template and the things that you have said already.Reply Only in English.give a detailed answer.
72
+ QUESTION: {question}
73
+ CONTEXT: {context}
74
+ CHAT HISTORY: {chat_history}[/INST]
75
+ ASSISTANT:
76
+ </s>
77
+ """
78
+
79
+ prompt = PromptTemplate(template=prompt_template,
80
+ input_variables=['question', 'context', 'chat_history'])
81
+
82
+ import os
83
+ os.environ['GOOGLE_API_KEY'] = "AIzaSyCIXtU3S3iGxsvPBbVhUUt3g23iL3hJuVs"
84
+ # google_api_key="AIzaSyCIXtU3S3iGxsvPBbVhUUt3g23iL3hJuVs"
85
+ # if not google_api_key:
86
+ # raise ValueError("GEMINI_API_KEY environment variable not set.")
87
+
88
+ llm = ChatGoogleGenerativeAI(model="gemini-1.5-flash")
89
+
90
+ # Create a conversational chain using only your database retriever
91
+ qa = ConversationalRetrievalChain.from_llm(
92
+ llm=llm,
93
+ memory=st.session_state.memory,
94
+ retriever=db_retriever,
95
+ combine_docs_chain_kwargs={'prompt': prompt}
96
+ )
97
+
98
+ for message in st.session_state.messages:
99
+ with st.chat_message(message.get("role")):
100
+ st.write(message.get("content"))
101
+
102
+ input_prompt = st.chat_input("Say something")
103
+
104
+ if input_prompt:
105
+ with st.chat_message("user"):
106
+ st.write(input_prompt)
107
+
108
+ st.session_state.messages.append({"role":"user","content":input_prompt})
109
+
110
+ with st.chat_message("assistant"):
111
+ with st.status("Lifting data, one bit at a time 💡🦾...",expanded=True):
112
+ result = qa.invoke(input=input_prompt)
113
+
114
+ message_placeholder = st.empty()
115
+
116
+ full_response = "⚠️ **_Note: Information provided may be inaccurate._** \n\n\n"
117
+ for chunk in result["answer"]:
118
+ full_response+=chunk
119
+ time.sleep(0.02)
120
+
121
+ message_placeholder.markdown(full_response+" ▌")
122
+ st.button('Reset All Chat 🗑️', on_click=reset_conversation)
123
+
124
+ st.session_state.messages.append({"role":"assistant","content":result["answer"]})
gym_vector_db/index.faiss ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40dc2703384c7b5c4023d86992e2a5b2e79bd09dd188e80f851e25b5ce5df24b
3
+ size 7253037
gym_vector_db/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16a2e580cab7ba89ce6727d80f7f48fb6532c58ffcdbbf021a5db9630dab750b
3
+ size 2117373
image.png ADDED
ingest.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv,find_dotenv
2
+ from transformers import pipeline
3
+ import os
4
+
5
+
6
+
7
+ load_dotenv(find_dotenv())
8
+
9
+
10
+ from langchain_community.document_loaders import PyPDFLoader, DirectoryLoader
11
+ from langchain.embeddings import HuggingFaceEmbeddings
12
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
13
+ from langchain_community.vectorstores import FAISS
14
+ import faiss
15
+ from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings
16
+
17
+ directory_path = "data" # Path to the directory containing your PDF files
18
+ loader = DirectoryLoader(directory_path, glob="./*.pdf", loader_cls=PyPDFLoader)
19
+ documents = loader.load()
20
+
21
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=1024, chunk_overlap=200)
22
+ texts = text_splitter.split_documents(documents)
23
+
24
+ # Create a SentenceTransformer object
25
+ embeddings = HuggingFaceEmbeddings(model_name="nomic-ai/nomic-embed-text-v1-ablated",model_kwargs={"trust_remote_code":True})
26
+
27
+
28
+ db = FAISS.from_documents(texts, embeddings)
29
+
30
+
31
+ db.save_local("gym_vector_db")
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ einops
2
+ langchain-groq
3
+ sentence_transformers
4
+ faiss-cpu
5
+ langchain-community
6
+ langchain
7
+ pypdf
8
+ huggingface_hub