Spaces:
Build error
Build error
Commit ·
8a04ad6
1
Parent(s): 101ce49
Upload 7 files
Browse files- apikey.py +4 -0
- app.py +57 -0
- gita.txt +0 -0
- icon.png +0 -0
- icon2.png +0 -0
- main.ipynb +0 -0
- requirements.txt +8 -0
apikey.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pinecone
|
| 2 |
+
llmkey="AIzaSyAV7sHdMEaR0H_Oy-KNJOKZoJcjmvuRheM"
|
| 3 |
+
def vec_db():
|
| 4 |
+
return pinecone.init(api_key='a95a55a1-a095-46df-93ae-0a84c865594f',environment='gcp-starter')
|
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import os
|
| 5 |
+
from sentence_transformers import SentenceTransformer
|
| 6 |
+
from langchain.vectorstores import Pinecone
|
| 7 |
+
import pinecone
|
| 8 |
+
from apikey import llmkey, vec_db
|
| 9 |
+
import os
|
| 10 |
+
#from langchain.llms import OpenAI
|
| 11 |
+
#from langchain.llms import GooglePalm
|
| 12 |
+
import google.generativeai as genai
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def get_text(prompt):
|
| 16 |
+
vec_db()
|
| 17 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 18 |
+
input_em = model.encode(prompt).tolist()
|
| 19 |
+
index=pinecone.Index('krishnaai')
|
| 20 |
+
output=index.query(input_em,top_k=2,includeMetadata=True).to_dict()
|
| 21 |
+
print(output['matches'][0]['metadata']['text']+output['matches'][1]['metadata']['text'])
|
| 22 |
+
return output['matches'][0]['metadata']['text']+output['matches'][1]['metadata']['text']
|
| 23 |
+
|
| 24 |
+
def get_LLMop(prompt):
|
| 25 |
+
os.environ["GEMINI_API_KEY"]=llmkey
|
| 26 |
+
gemini_api_key = os.environ["GEMINI_API_KEY"]
|
| 27 |
+
genai.configure(api_key = gemini_api_key)
|
| 28 |
+
#llm=GooglePalm()
|
| 29 |
+
|
| 30 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 31 |
+
response = model.generate_content("Who is the GOAT in the Football?")
|
| 32 |
+
|
| 33 |
+
ans=model.generate_content([get_text(prompt)+'use these text if possible and guide me {prompt}. Answer me as you are Lord Krishna,answer should be should be very short,highly creative and with a simple English'])
|
| 34 |
+
return ans.text
|
| 35 |
+
|
| 36 |
+
st.title("Krishna AI")
|
| 37 |
+
|
| 38 |
+
image = Image.open('icon.png')
|
| 39 |
+
image2 = Image.open('icon2.png')
|
| 40 |
+
#message = st.chat_message(name='Krishna',avatar=image)
|
| 41 |
+
with st.chat_message("Krishna",avatar=image):
|
| 42 |
+
st.markdown("Hey Bhakth,how can I help you")
|
| 43 |
+
|
| 44 |
+
if "messages" not in st.session_state:
|
| 45 |
+
st.session_state.messages=[]
|
| 46 |
+
for message in st.session_state.messages:
|
| 47 |
+
with st.chat_message(message['role']):
|
| 48 |
+
st.markdown(message['content'])
|
| 49 |
+
prompt=st.chat_input('Ask me for moksha')
|
| 50 |
+
if prompt:
|
| 51 |
+
with st.chat_message("user",avatar=image2):
|
| 52 |
+
st.markdown(prompt)
|
| 53 |
+
st.session_state.messages.append({"role":"user","content":prompt})
|
| 54 |
+
response=get_LLMop(prompt)
|
| 55 |
+
with st.chat_message("Krishna",avatar=image):
|
| 56 |
+
st.markdown(response)
|
| 57 |
+
st.session_state.messages.append({"role":"Krishna","content":response})
|
gita.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
icon.png
ADDED
|
|
icon2.png
ADDED
|
|
main.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pip==23.3
|
| 2 |
+
langchain==0.0.311
|
| 3 |
+
numpy==1.22.3
|
| 4 |
+
Pillow==9.5.0
|
| 5 |
+
sentence_transformers==2.2.2
|
| 6 |
+
streamlit==1.27.0
|
| 7 |
+
pinecone-client==2.2.4
|
| 8 |
+
google-generativeai==0.3.2
|