saswattulo commited on
Commit
b3f615c
β€’
1 Parent(s): f4e28a0

Upload 4 files

Browse files
Files changed (4) hide show
  1. requirements.txt +152 -0
  2. secure-connect-temp-db.zip +3 -0
  3. temp_db-token.json +5 -0
  4. test.py +109 -0
requirements.txt ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aenum==3.1.15
2
+ aiohttp==3.9.3
3
+ aiosignal==1.3.1
4
+ aiostream==0.5.2
5
+ altair==4.2.2
6
+ annotated-types==0.6.0
7
+ anyio==4.2.0
8
+ asttokens==2.4.1
9
+ async-timeout==4.0.3
10
+ attrs==23.2.0
11
+ beautifulsoup4==4.12.3
12
+ bleach==6.1.0
13
+ blinker==1.7.0
14
+ cachetools==5.3.2
15
+ cassandra-driver==3.29.0
16
+ certifi==2024.2.2
17
+ charset-normalizer==3.3.2
18
+ click==8.1.7
19
+ colorama==0.4.6
20
+ comm==0.2.1
21
+ contourpy==1.2.0
22
+ cycler==0.12.1
23
+ dataclasses-json==0.5.14
24
+ debugpy==1.8.1
25
+ decorator==5.1.1
26
+ defusedxml==0.7.1
27
+ Deprecated==1.2.14
28
+ distro==1.9.0
29
+ entrypoints==0.4
30
+ exceptiongroup==1.2.0
31
+ executing==2.0.1
32
+ faiss-cpu==1.7.4
33
+ Faker==23.2.1
34
+ fastjsonschema==2.19.1
35
+ favicon==0.7.0
36
+ fonttools==4.49.0
37
+ frozenlist==1.4.1
38
+ fsspec==2024.2.0
39
+ geomet==0.2.1.post1
40
+ gitdb==4.0.11
41
+ GitPython==3.1.41
42
+ gradientai==1.7.0
43
+ greenlet==3.0.3
44
+ h11==0.14.0
45
+ htbuilder==0.6.2
46
+ httpcore==1.0.2
47
+ httpx==0.26.0
48
+ idna==3.6
49
+ importlib-metadata==7.0.1
50
+ ipykernel==6.29.2
51
+ jedi==0.19.1
52
+ Jinja2==3.1.3
53
+ joblib==1.3.2
54
+ jsonschema==4.21.1
55
+ jsonschema-specifications==2023.12.1
56
+ jupyter_client==8.6.0
57
+ jupyter_core==5.7.1
58
+ jupyterlab_pygments==0.3.0
59
+ kiwisolver==1.4.5
60
+ langchain==0.0.154
61
+ llama-index==0.9.12
62
+ lxml==5.1.0
63
+ Markdown==3.5.2
64
+ markdown-it-py==3.0.0
65
+ markdownlit==0.0.7
66
+ MarkupSafe==2.1.5
67
+ marshmallow==3.20.2
68
+ matplotlib==3.8.3
69
+ matplotlib-inline==0.1.6
70
+ mdurl==0.1.2
71
+ mistune==3.0.2
72
+ more-itertools==10.2.0
73
+ multidict==6.0.5
74
+ mypy-extensions==1.0.0
75
+ nbclient==0.9.0
76
+ nbconvert==7.16.0
77
+ nbformat==5.9.2
78
+ nest-asyncio==1.6.0
79
+ nltk==3.8.1
80
+ numexpr==2.9.0
81
+ numpy==1.26.4
82
+ openai==1.12.0
83
+ openapi-schema-pydantic==1.2.4
84
+ packaging==23.2
85
+ pandas==2.2.0
86
+ pandocfilters==1.5.1
87
+ parso==0.8.3
88
+ pillow==10.2.0
89
+ platformdirs==4.2.0
90
+ prometheus_client==0.20.0
91
+ prompt-toolkit==3.0.43
92
+ protobuf==3.20.3
93
+ psutil==5.9.8
94
+ pure-eval==0.2.2
95
+ pyarrow==15.0.0
96
+ pydantic==1.10.14
97
+ pydantic_core==2.16.2
98
+ pydeck==0.8.1b0
99
+ Pygments==2.17.2
100
+ pymdown-extensions==10.7
101
+ Pympler==1.0.1
102
+ pyparsing==3.1.1
103
+ pypdf==4.0.1
104
+ PyPDF2==3.0.1
105
+ python-dateutil==2.8.2
106
+ python-dotenv==1.0.0
107
+ pytz==2024.1
108
+ PyYAML==6.0.1
109
+ pyzmq==25.1.2
110
+ referencing==0.33.0
111
+ regex==2023.12.25
112
+ requests==2.31.0
113
+ rich==13.7.0
114
+ rpds-py==0.17.1
115
+ semver==3.0.2
116
+ six==1.16.0
117
+ smmap==5.0.1
118
+ sniffio==1.3.0
119
+ soupsieve==2.5
120
+ SQLAlchemy==2.0.27
121
+ st-annotated-text==4.0.1
122
+ stack-data==0.6.3
123
+ streamlit==1.31.1
124
+ streamlit-camera-input-live==0.2.0
125
+ streamlit-card==1.0.0
126
+ streamlit-embedcode==0.1.2
127
+ streamlit-extras==0.4.0
128
+ streamlit-faker==0.0.3
129
+ streamlit-image-coordinates==0.1.6
130
+ streamlit-keyup==0.2.3
131
+ streamlit-toggle-switch==1.0.2
132
+ streamlit-vertical-slider==2.5.5
133
+ tenacity==8.2.3
134
+ tiktoken==0.6.0
135
+ tinycss2==1.2.1
136
+ toml==0.10.2
137
+ toolz==0.12.1
138
+ tornado==6.4
139
+ tqdm==4.66.2
140
+ traitlets==5.14.1
141
+ typing-inspect==0.9.0
142
+ typing_extensions==4.9.0
143
+ tzdata==2024.1
144
+ tzlocal==5.2
145
+ urllib3==2.2.0
146
+ validators==0.22.0
147
+ watchdog==4.0.0
148
+ wcwidth==0.2.13
149
+ webencodings==0.5.1
150
+ wrapt==1.16.0
151
+ yarl==1.9.4
152
+ zipp==3.17.0
secure-connect-temp-db.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:95aa8a081f163bff17243230a0a82175ec593f0a10e4ace26d3afcf0b2fa19ae
3
+ size 12260
temp_db-token.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "clientId": "nsJkarPpFtcNCEzGatNGTttm",
3
+ "secret": "x9+CWlAOHuwtWKG6XY1Iv32THHlHSC.ZyB+-g+BaDZdWrAz7ZC01PdjaIzBO7OvIJvaLzglSmcOWjN2PAXbuS4uKT7Gq7kDMY4hwqovANflyA4xgW9ao-0FQqZnN4yG+",
4
+ "token": "AstraCS:nsJkarPpFtcNCEzGatNGTttm:caf63b39a1eab4ba6e6bc99ba7b66ed549a7f0509080f7868140e4c3f472ee40"
5
+ }
test.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import streamlit as st
4
+ from cassandra.auth import PlainTextAuthProvider
5
+ from cassandra.cluster import Cluster
6
+ from llama_index import ServiceContext
7
+ from llama_index import set_global_service_context
8
+ from llama_index import VectorStoreIndex, SimpleDirectoryReader, StorageContext
9
+ from llama_index.embeddings import GradientEmbedding
10
+ from llama_index.llms import GradientBaseModelLLM
11
+ from llama_index.vector_stores import CassandraVectorStore
12
+ from copy import deepcopy
13
+ from tempfile import NamedTemporaryFile
14
+
15
+ os.environ['GRADIENT_ACCESS_TOKEN'] = "sevG6Rqb0ztaquM4xjr83SBNSYj91cux"
16
+ os.environ['GRADIENT_WORKSPACE_ID'] = "4de36c1f-5ee6-41da-8f95-9d2fb1ded33a_workspace"
17
+
18
+ @st.cache_resource
19
+ def create_datastax_connection():
20
+
21
+ cloud_config= {'secure_connect_bundle': 'secure-connect-temp-db.zip'}
22
+
23
+ with open("temp_db-token.json") as f:
24
+ secrets = json.load(f)
25
+
26
+ CLIENT_ID = secrets["clientId"]
27
+ CLIENT_SECRET = secrets["secret"]
28
+
29
+ auth_provider = PlainTextAuthProvider(CLIENT_ID, CLIENT_SECRET)
30
+ cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
31
+ astra_session = cluster.connect()
32
+ return astra_session
33
+
34
+ def main():
35
+
36
+ index_placeholder = None
37
+ st.set_page_config(page_title = "NyayMitra", page_icon="πŸ¦™")
38
+ st.header('NyayMitra')
39
+
40
+ if "conversation" not in st.session_state:
41
+ st.session_state.conversation = None
42
+
43
+ if "activate_chat" not in st.session_state:
44
+ st.session_state.activate_chat = False
45
+
46
+ if "messages" not in st.session_state:
47
+ st.session_state.messages = []
48
+
49
+ for message in st.session_state.messages:
50
+ with st.chat_message(message["role"], avatar = message['avatar']):
51
+ st.markdown(message["content"])
52
+
53
+ session = create_datastax_connection()
54
+
55
+ os.environ['GRADIENT_ACCESS_TOKEN'] = "sevG6Rqb0ztaquM4xjr83SBNSYj91cux"
56
+ os.environ['GRADIENT_WORKSPACE_ID'] = "4de36c1f-5ee6-41da-8f95-9d2fb1ded33a_workspace"
57
+
58
+ llm = GradientBaseModelLLM(base_model_slug="llama2-7b-chat", max_tokens=400)
59
+
60
+ embed_model = GradientEmbedding(
61
+ gradient_access_token = os.environ["GRADIENT_ACCESS_TOKEN"],
62
+ gradient_workspace_id = os.environ["GRADIENT_WORKSPACE_ID"],
63
+ gradient_model_slug="bge-large")
64
+
65
+ service_context = ServiceContext.from_defaults(
66
+ llm = llm,
67
+ embed_model = embed_model,
68
+ chunk_size=256)
69
+
70
+ set_global_service_context(service_context)
71
+
72
+ with st.sidebar:
73
+ st.subheader('Start your chat here')
74
+ if st.button('Process'):
75
+ with st.spinner('Processing'):
76
+ reader = 'data'
77
+
78
+ documents = SimpleDirectoryReader(reader).load_data()
79
+ index = VectorStoreIndex.from_documents(documents,
80
+ service_context=service_context)
81
+ query_engine = index.as_query_engine()
82
+ if "query_engine" not in st.session_state:
83
+ st.session_state.query_engine = query_engine
84
+ st.session_state.activate_chat = True
85
+
86
+ if st.session_state.activate_chat == True:
87
+ if prompt := st.chat_input("Ask your question"):
88
+ with st.chat_message("user", avatar = 'πŸ‘¨πŸ»'):
89
+ st.markdown(prompt)
90
+ st.session_state.messages.append({"role": "user",
91
+ "avatar" :'πŸ‘¨πŸ»',
92
+ "content": prompt})
93
+
94
+ query_index_placeholder = st.session_state.query_engine
95
+ pdf_response = query_index_placeholder.query(prompt)
96
+ cleaned_response = pdf_response.response
97
+ with st.chat_message("assistant", avatar='πŸ€–'):
98
+ st.markdown(cleaned_response)
99
+ st.session_state.messages.append({"role": "assistant",
100
+ "avatar" :'πŸ€–',
101
+ "content": cleaned_response})
102
+ else:
103
+ st.markdown(
104
+ ' '
105
+ )
106
+
107
+
108
+ if __name__ == '__main__':
109
+ main()