Spaces:
Sleeping
Sleeping
Upload 72 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +34 -0
- Dataset/Drama/Broken_images.pdf +3 -0
- Dataset/Drama/Chandalika.pdf +3 -0
- Dataset/Poems/A_lecture_upon_the_shadow.pdf +3 -0
- Dataset/Poems/Blood.pdf +3 -0
- Dataset/Poems/Kubla_khan.pdf +3 -0
- Dataset/Poems/On_time.pdf +3 -0
- Dataset/Poems/The_divine_image.pdf +3 -0
- Dataset/Poems/The_wild_swans_at_coole.pdf +3 -0
- Dataset/Poems/Time_and_time_again.pdf +3 -0
- Dataset/Poems/Trees_emily_dickinson.pdf +3 -0
- Dataset/Stories/A_wedding_in_brownsville.pdf +3 -0
- Dataset/Stories/I_sell_my_dreams.pdf +3 -0
- Dataset/Stories/One_centimetre.pdf +3 -0
- Dataset/Stories/Tomorrow.pdf +3 -0
- Dataset/Stories/eveline.pdf +3 -0
- Dataset/non_fiction/Flim_making.pdf +3 -0
- Dataset/non_fiction/Freedom_freedom.pdf +3 -0
- Dataset/non_fiction/On_science_fiction.pdf +3 -0
- Dataset/non_fiction/The_argumentative_indian.pdf +3 -0
- Dataset/non_fiction/The_mark_on_the_wall.pdf +3 -0
- Dataset/non_fiction/Why_the_novel_matters.pdf +3 -0
- README.md +6 -4
- app.py +181 -0
- chapter_index.pkl +3 -0
- chat_engine.py +45 -0
- custom_prompt.pkl +3 -0
- index_dict.pkl +3 -0
- prompt_engg.pkl +3 -0
- qdrant/a_lecture_upon_the_shadow/collection/A Lecture Upon The Shadow/storage.sqlite +0 -0
- qdrant/a_lecture_upon_the_shadow/meta.json +1 -0
- qdrant/a_wedding_in_brownsville/collection/A Wedding In Brownsville/storage.sqlite +3 -0
- qdrant/a_wedding_in_brownsville/meta.json +1 -0
- qdrant/blood/collection/Blood/storage.sqlite +0 -0
- qdrant/blood/meta.json +1 -0
- qdrant/broken_images/collection/Broken Images/storage.sqlite +3 -0
- qdrant/broken_images/meta.json +1 -0
- qdrant/chandalika/collection/Chandalika/storage.sqlite +3 -0
- qdrant/chandalika/meta.json +1 -0
- qdrant/eveline/collection/Eveline/storage.sqlite +3 -0
- qdrant/eveline/meta.json +1 -0
- qdrant/film_making/collection/Flim Making/storage.sqlite +3 -0
- qdrant/film_making/meta.json +1 -0
- qdrant/freedom/collection/Freedom/storage.sqlite +3 -0
- qdrant/freedom/meta.json +1 -0
- qdrant/i_sell_my_dreams/collection/I Sell My Dreams/storage.sqlite +3 -0
- qdrant/i_sell_my_dreams/meta.json +1 -0
- qdrant/kubla_khan/collection/Kubla Khan/storage.sqlite +0 -0
- qdrant/kubla_khan/meta.json +1 -0
- qdrant/on_science_fiction/collection/On Science Fiction/storage.sqlite +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,37 @@ 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 |
+
Dataset/Drama/Broken_images.pdf filter=lfs diff=lfs merge=lfs -text
|
37 |
+
Dataset/Drama/Chandalika.pdf filter=lfs diff=lfs merge=lfs -text
|
38 |
+
Dataset/non_fiction/Flim_making.pdf filter=lfs diff=lfs merge=lfs -text
|
39 |
+
Dataset/non_fiction/Freedom_freedom.pdf filter=lfs diff=lfs merge=lfs -text
|
40 |
+
Dataset/non_fiction/On_science_fiction.pdf filter=lfs diff=lfs merge=lfs -text
|
41 |
+
Dataset/non_fiction/The_argumentative_indian.pdf filter=lfs diff=lfs merge=lfs -text
|
42 |
+
Dataset/non_fiction/The_mark_on_the_wall.pdf filter=lfs diff=lfs merge=lfs -text
|
43 |
+
Dataset/non_fiction/Why_the_novel_matters.pdf filter=lfs diff=lfs merge=lfs -text
|
44 |
+
Dataset/Poems/A_lecture_upon_the_shadow.pdf filter=lfs diff=lfs merge=lfs -text
|
45 |
+
Dataset/Poems/Blood.pdf filter=lfs diff=lfs merge=lfs -text
|
46 |
+
Dataset/Poems/Kubla_khan.pdf filter=lfs diff=lfs merge=lfs -text
|
47 |
+
Dataset/Poems/On_time.pdf filter=lfs diff=lfs merge=lfs -text
|
48 |
+
Dataset/Poems/The_divine_image.pdf filter=lfs diff=lfs merge=lfs -text
|
49 |
+
Dataset/Poems/The_wild_swans_at_coole.pdf filter=lfs diff=lfs merge=lfs -text
|
50 |
+
Dataset/Poems/Time_and_time_again.pdf filter=lfs diff=lfs merge=lfs -text
|
51 |
+
Dataset/Poems/Trees_emily_dickinson.pdf filter=lfs diff=lfs merge=lfs -text
|
52 |
+
Dataset/Stories/A_wedding_in_brownsville.pdf filter=lfs diff=lfs merge=lfs -text
|
53 |
+
Dataset/Stories/eveline.pdf filter=lfs diff=lfs merge=lfs -text
|
54 |
+
Dataset/Stories/I_sell_my_dreams.pdf filter=lfs diff=lfs merge=lfs -text
|
55 |
+
Dataset/Stories/One_centimetre.pdf filter=lfs diff=lfs merge=lfs -text
|
56 |
+
Dataset/Stories/Tomorrow.pdf filter=lfs diff=lfs merge=lfs -text
|
57 |
+
qdrant/a_wedding_in_brownsville/collection/A[[:space:]]Wedding[[:space:]]In[[:space:]]Brownsville/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
58 |
+
qdrant/broken_images/collection/Broken[[:space:]]Images/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
59 |
+
qdrant/chandalika/collection/Chandalika/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
60 |
+
qdrant/eveline/collection/Eveline/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
61 |
+
qdrant/film_making/collection/Flim[[:space:]]Making/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
62 |
+
qdrant/freedom/collection/Freedom/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
63 |
+
qdrant/i_sell_my_dreams/collection/I[[:space:]]Sell[[:space:]]My[[:space:]]Dreams/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
64 |
+
qdrant/on_science_fiction/collection/On[[:space:]]Science[[:space:]]Fiction/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
65 |
+
qdrant/one_centimeter/collection/One[[:space:]]Centimeter/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
66 |
+
qdrant/the_argumentative_indian/collection/The[[:space:]]Argumentative[[:space:]]Indian/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
67 |
+
qdrant/the_mark_on_the_wall/collection/The[[:space:]]Mark[[:space:]]On[[:space:]]The[[:space:]]Wall/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
68 |
+
qdrant/tomorrow/collection/Tomorrow/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
69 |
+
qdrant/why_the_novel_matters/collection/Why[[:space:]]The[[:space:]]Novel[[:space:]]Matters/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
Dataset/Drama/Broken_images.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:eb3d1033a5062055b07e220b953bef98c826325053a98071f752032cb05d2151
|
3 |
+
size 1205904
|
Dataset/Drama/Chandalika.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3b799d4ecd66890c86b731bfe4cc7509dcce80f2b6ca58ab38ca6d670a14c668
|
3 |
+
size 1503804
|
Dataset/Poems/A_lecture_upon_the_shadow.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4d3dad7ab79d04266074f1b81dff5b2d92ebb62e68bfb25f739cbe5bb6e94565
|
3 |
+
size 427016
|
Dataset/Poems/Blood.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ee043a03370a5363fc8c48e259efd80dcc93374dcb55ed4cd1f5765e26503344
|
3 |
+
size 445656
|
Dataset/Poems/Kubla_khan.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:25fad91d337387e3a918877bb1e6984b2d54c6b85f35c726b3717fb0a3238caa
|
3 |
+
size 395237
|
Dataset/Poems/On_time.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d489a5656a33fba7a730d36d38f119ca68982a830bc7aa7fa2258cdcf59a2ed6
|
3 |
+
size 326945
|
Dataset/Poems/The_divine_image.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:67b9b33ef53a427b0738d4e14da9ec2a91ad78c4c13862d6a55d7d1ba4166766
|
3 |
+
size 2087736
|
Dataset/Poems/The_wild_swans_at_coole.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1348796ce97323c2ab35a30e9c5d6e76659e8b564adfcc6903b44884e39c6d18
|
3 |
+
size 244804
|
Dataset/Poems/Time_and_time_again.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:093d7857e04e73576ae5bc806ea4610a67c0a863b01284408d0b610acfb2ce43
|
3 |
+
size 286347
|
Dataset/Poems/Trees_emily_dickinson.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:feda4a8cf83af6ab8ae30dfc37d9e287cee8b7bd7846098dbf07b3e5d2e73eef
|
3 |
+
size 282261
|
Dataset/Stories/A_wedding_in_brownsville.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d823be10f9ec9371998980df5f9c95ba5f6c5df623bfdf709d2d1bb8fa05f320
|
3 |
+
size 1320450
|
Dataset/Stories/I_sell_my_dreams.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d1b5dbf330b6c2f0521e29527490f4703c6a9828202f6caac66ed3cef51f3c58
|
3 |
+
size 866980
|
Dataset/Stories/One_centimetre.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3cf42598f64075f8a798884163521e2d5a2d261f7c42a5a59bf3ccffe67363a3
|
3 |
+
size 1514845
|
Dataset/Stories/Tomorrow.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d8402b929756b19fd4b00711e08d402c8d7c06510d9b96f398d52a762494413a
|
3 |
+
size 2223787
|
Dataset/Stories/eveline.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:de6561016ab5f2ce4539f6fb482e5e1b4fbb49071e839e81d79aa33304566420
|
3 |
+
size 811025
|
Dataset/non_fiction/Flim_making.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c831a45de18aac2a1c91e5927771afe88149dcee0f52a122acee62d60c12237c
|
3 |
+
size 1310774
|
Dataset/non_fiction/Freedom_freedom.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ab53c4540e908cc3b5ba5873eeed3e583dab169f45c0ed3599be132c85a36927
|
3 |
+
size 1303640
|
Dataset/non_fiction/On_science_fiction.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e41d663560cba7602e4a474340f5749b1946f6a059249ac1ae7e741aa4381ca2
|
3 |
+
size 925262
|
Dataset/non_fiction/The_argumentative_indian.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f7c23fafb8b3a9bc0ebcc917b0a1fc391eee2a1d23483a449b40c15270bb1c21
|
3 |
+
size 1114494
|
Dataset/non_fiction/The_mark_on_the_wall.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4563eec7df95e63ac35b5df0532000f323df9b2b41d526e07464e0ed740cf5ad
|
3 |
+
size 954787
|
Dataset/non_fiction/Why_the_novel_matters.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:aa82bf32a32b8a6c92a496c7d240eff83e1262c32475899b53ae28c9abf323bb
|
3 |
+
size 864079
|
README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
|
|
10 |
---
|
11 |
|
12 |
-
|
|
|
1 |
---
|
2 |
+
title: KaleidoscopeChat
|
3 |
+
emoji: 💬
|
4 |
colorFrom: yellow
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.0.1
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: mit
|
11 |
+
short_description: 'KaleidoscopChat answers queries: NCERT 12th Textbook.'
|
12 |
---
|
13 |
|
14 |
+
An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|
app.py
ADDED
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
#from langchain_openai import ChatOpenAI
|
4 |
+
from langchain_groq import ChatGroq
|
5 |
+
from langchain_core.runnables import Runnable
|
6 |
+
from chat_engine import conversation_prompt
|
7 |
+
from chat_engine import chapter_index
|
8 |
+
from chat_engine import tree_index_list
|
9 |
+
from chat_engine import select_index
|
10 |
+
from langchain_core.messages import SystemMessage, HumanMessage, AIMessage
|
11 |
+
from pathlib import Path
|
12 |
+
#from chat_engine import prompt_query
|
13 |
+
|
14 |
+
groq_llm = ChatGroq(
|
15 |
+
model_name="llama-3.3-70b-versatile",
|
16 |
+
temperature=0.2,
|
17 |
+
api_key=os.getenv('GROQ_API_KEY')
|
18 |
+
)
|
19 |
+
|
20 |
+
response_chain: Runnable = conversation_prompt | groq_llm
|
21 |
+
|
22 |
+
#groq_user_engg=ChatGroq(
|
23 |
+
# model_name="llama3-70b-8192",
|
24 |
+
# temperature=0,
|
25 |
+
# api_key=os.getenv("GROQ_API")
|
26 |
+
#)
|
27 |
+
|
28 |
+
#query_chain: Runnable = prompt_query | groq_user_engg
|
29 |
+
|
30 |
+
def gradio_chat(user_query, chat_history, index, tree_index_list=tree_index_list, chapter_index=chapter_index,response_chain=response_chain):
|
31 |
+
|
32 |
+
if chat_history is None:
|
33 |
+
chat_history=[]
|
34 |
+
|
35 |
+
if user_query=="":
|
36 |
+
chat_history.append(HumanMessage(user_query))
|
37 |
+
chat_history.append(AIMessage("Kindly ask a question from the selected chapter."))
|
38 |
+
return "Kindly ask a question from the selected chapter", chat_history
|
39 |
+
|
40 |
+
vector_index=select_index(index)
|
41 |
+
retriever1=vector_index.as_retriever(similarity_top_k=2)
|
42 |
+
retrieved_nodes1=retriever1.retrieve(user_query)
|
43 |
+
|
44 |
+
tree_index=tree_index_list[chapter_index[retrieved_nodes1[0].metadata["chapter"]]]
|
45 |
+
if retrieved_nodes1[0].metadata["section"]=="poem":
|
46 |
+
retriever = tree_index.as_retriever(similarity_top_k=4, retriever_mode="all_leaf")
|
47 |
+
retrieved_nodes3=retriever.retrieve("summarize the poem")
|
48 |
+
#answer = response_synthesizer.synthesize(query=user_query, nodes=retrieved_nodes3)
|
49 |
+
pext=""
|
50 |
+
for content in retrieved_nodes3:
|
51 |
+
pext=pext+' '+content.text.strip()
|
52 |
+
context='Author: '+retrieved_nodes1[0].metadata['author']+'\nSection: '+retrieved_nodes1[0].metadata['section']+'\nChapter: '+retrieved_nodes1[0].metadata['chapter']+'\nContext: '+pext
|
53 |
+
|
54 |
+
else:
|
55 |
+
contextt=[]
|
56 |
+
for text in retrieved_nodes1:
|
57 |
+
contextt.append((text.metadata['page'], text.text))
|
58 |
+
contextt.sort(key=lambda x:x[0])
|
59 |
+
context1=[x[1] for x in contextt]
|
60 |
+
|
61 |
+
retriever = tree_index.as_retriever(similarity_top_k=1,retriever_mode="root",
|
62 |
+
search_kwargs={"num_children":3})
|
63 |
+
|
64 |
+
retrieved_nodes2=retriever.retrieve("summarize this chapter")
|
65 |
+
|
66 |
+
for text in retrieved_nodes2:
|
67 |
+
context1.append(text.text.strip())
|
68 |
+
context="\n".join(context1)
|
69 |
+
context='Author: '+retrieved_nodes1[0].metadata['author']+'\nSection: '+retrieved_nodes1[0].metadata['section']+'\nChapter: '+retrieved_nodes1[0].metadata['chapter']+'\nContext: '+context
|
70 |
+
|
71 |
+
chat_history.append(HumanMessage(user_query))
|
72 |
+
response=response_chain.invoke({"chat_history":chat_history[-12:], "user_query":user_query, "document_context":context})
|
73 |
+
chat_history.append(AIMessage(response.content))
|
74 |
+
|
75 |
+
return response.content, chat_history
|
76 |
+
|
77 |
+
#def prompt_engg(message, chain_history, index, previous_index="Broken Images"):
|
78 |
+
|
79 |
+
#if previous_index == index:
|
80 |
+
#index_change=0
|
81 |
+
#else:
|
82 |
+
#index_change=1
|
83 |
+
#question=query_chain.invoke({"user_query":message, "chat_history":chain_history, "index":index, "index_change":index_change})
|
84 |
+
|
85 |
+
#return question.content
|
86 |
+
|
87 |
+
def respond(message, chain_history, ui_history, index):
|
88 |
+
|
89 |
+
ui_history.append({"role": "user", "content": message})
|
90 |
+
#message=prompt_engg(message, chain_history, index)
|
91 |
+
response_text, updated_history = gradio_chat(message, chain_history, index=index)
|
92 |
+
|
93 |
+
if ui_history is None:
|
94 |
+
ui_history = []
|
95 |
+
|
96 |
+
ui_history.append({"role": "assistant", "content": response_text})
|
97 |
+
#print(ui_history)
|
98 |
+
return "", updated_history, ui_history
|
99 |
+
|
100 |
+
def download_file(index):
|
101 |
+
filepath=chapter_dir[index]
|
102 |
+
return filepath
|
103 |
+
|
104 |
+
custom_css = """
|
105 |
+
#chatbot_interface {
|
106 |
+
background: #f0f0f0;
|
107 |
+
padding: 20px;
|
108 |
+
border-radius: 10px;
|
109 |
+
}
|
110 |
+
|
111 |
+
/* Center the markdown text */
|
112 |
+
#welcome_markdown {
|
113 |
+
text-align: center;
|
114 |
+
margin: auto;
|
115 |
+
}
|
116 |
+
"""
|
117 |
+
|
118 |
+
with gr.Blocks(css=custom_css,fill_width=True) as demo:
|
119 |
+
gr.Markdown("""
|
120 |
+
# I’m Shalini ☺️ #
|
121 |
+
Your Creative Muse — Where Literature Dances, Art Breathes, and Philosophy Whispers 🎨📖🪞
|
122 |
+
|
123 |
+
Welcome to *Kaleidoscope* —
|
124 |
+
Where words don’t just sit still — they swirl, they shimmer, they *sing*.
|
125 |
+
Have a question from the 12th NCERT English textbook *Kaleidoscope*?
|
126 |
+
Ask — and I’ll reply with words that wander, wonder, and land like truth. 📚🌿
|
127 |
+
---
|
128 |
+
Let’s begin this soulful journey together:
|
129 |
+
1. Pick your chapter from the dropdown below.
|
130 |
+
2. Step into the story with your question.
|
131 |
+
3. I’ll craft a reply — rhythmic, radiant, and rich with meaning. 🖼️💫
|
132 |
+
""",elem_id="welcome_markdown")
|
133 |
+
|
134 |
+
chapter_dir={"Broken Images":"Dataset/Drama/Broken_images.pdf",
|
135 |
+
"Blood":"Dataset/Poems/Blood.pdf",
|
136 |
+
"Flim Making":"Dataset/non_fiction/Flim_making.pdf",
|
137 |
+
"Kubla Khan":"Dataset/Poems/Kubla_khan.pdf",
|
138 |
+
"One Centimeter":"Dataset/Stories/One_centimetre.pdf",
|
139 |
+
"I Sell My Dreams":"Dataset/Stories/I_sell_my_dreams.pdf",
|
140 |
+
"Poems By Blake":"Dataset/Poems/The_divine_image.pdf",
|
141 |
+
"Time and Time Again":"Dataset/Poems/Time_and_time_again.pdf",
|
142 |
+
"On Time":"Dataset/Poems/On_time.pdf",
|
143 |
+
"Trees":"Dataset/Poems/Trees_emily_dickinson.pdf",
|
144 |
+
"On Science Fiction":"Dataset/non_fiction/On_science_fiction.pdf",
|
145 |
+
"The Argumentative Indian":"Dataset/non_fiction/The_argumentative_indian.pdf",
|
146 |
+
"Why The Novel Matters":"Dataset/non_fiction/Why_the_novel_matters.pdf",
|
147 |
+
"Tomorrow":"Dataset/Stories/Tomorrow.pdf",
|
148 |
+
"A Lecture Upon The Shadow":"Dataset/Poems/A_lecture_upon_the_shadow.pdf",
|
149 |
+
"Freedom":"Dataset/non_fiction/Freedom_freedom.pdf",
|
150 |
+
"A Wedding in Brownsville":"Dataset/Stories/A_wedding_in_brownsville.pdf",
|
151 |
+
"Eveline":"Dataset/Stories/eveline.pdf",
|
152 |
+
"Chandalika":"Dataset/Drama/Chandalika.pdf",
|
153 |
+
"The Wild Swans At Coole":"Dataset/Poems/The_wild_swans_at_coole.pdf",
|
154 |
+
"The Mark On The Wall":"Dataset/non_fiction/The_mark_on_the_wall.pdf"}
|
155 |
+
|
156 |
+
chatbot = gr.Chatbot(label="Chat Interface", elem_id="chatbot_interface", type="messages")
|
157 |
+
|
158 |
+
index=gr.State()
|
159 |
+
with gr.Row():
|
160 |
+
index=gr.Dropdown(
|
161 |
+
choices=list(chapter_dir.keys()),
|
162 |
+
label="Chapter",
|
163 |
+
value="Broken Images",
|
164 |
+
info="Select the chapter on which you would like to ask questions."
|
165 |
+
)
|
166 |
+
msg = gr.Textbox(label="Enter your query:", placeholder="Type your question here...", lines=2)
|
167 |
+
|
168 |
+
d = gr.DownloadButton("Download Selected Chapter", visible=True)
|
169 |
+
index.change(fn=download_file, inputs=index, outputs=d)
|
170 |
+
#d.click(download_file, index, [d])
|
171 |
+
|
172 |
+
chain_history = gr.State([]) # For LangChain message objects
|
173 |
+
ui_history = gr.State([]) # For display, a list of dictionaries
|
174 |
+
|
175 |
+
gr.Button("Glide In🎨").click(respond, [msg, chain_history, ui_history, index], [msg, chain_history, chatbot])
|
176 |
+
|
177 |
+
#clear = gr.ClearButton([msg, chatbot], size="sm")
|
178 |
+
msg.submit(fn=respond, inputs=[msg, chain_history, ui_history, index], outputs=[msg, chain_history, chatbot])
|
179 |
+
|
180 |
+
demo.launch(allowed_paths=["Dataset/Stories","Dataset/Drama",
|
181 |
+
"Dataset/Poems","Dataset/non_fiction"])
|
chapter_index.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:af263e6420b881ef922552239f3c0409c448b712c71ffbb75a35780255773ff9
|
3 |
+
size 491
|
chat_engine.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
from langchain_core.prompts import ChatPromptTemplate
|
3 |
+
from langchain_core.runnables import Runnable
|
4 |
+
from langchain_openai import ChatOpenAI
|
5 |
+
from timeit import default_timer as timer
|
6 |
+
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
7 |
+
from qdrant_client import QdrantClient
|
8 |
+
from llama_index.vector_stores.qdrant import QdrantVectorStore
|
9 |
+
from llama_index.core import StorageContext, VectorStoreIndex
|
10 |
+
|
11 |
+
with open("custom_prompt.pkl", "rb") as file:
|
12 |
+
custom_template=pickle.load(file)
|
13 |
+
|
14 |
+
with open("tree_index_list.pkl","rb") as f:
|
15 |
+
tree_index_list=pickle.load(f)
|
16 |
+
|
17 |
+
with open("chapter_index.pkl","rb") as f:
|
18 |
+
chapter_index=pickle.load(f)
|
19 |
+
|
20 |
+
with open("index_dict.pkl", "rb") as file:
|
21 |
+
index_dict=pickle.load(file)
|
22 |
+
|
23 |
+
conversation_prompt=ChatPromptTemplate.from_template(template=custom_template)
|
24 |
+
|
25 |
+
#with open("prompt_engg.pkl", "rb") as file:
|
26 |
+
# prompt_engg=pickle.load(file)
|
27 |
+
|
28 |
+
#prompt_query=ChatPromptTemplate.from_template(template=prompt_engg)
|
29 |
+
|
30 |
+
embedding_function = HuggingFaceEmbedding(model_name="sentence-transformers/all-roberta-large-v1")
|
31 |
+
|
32 |
+
def select_index(index, index_dict=index_dict, embedding_function=embedding_function):
|
33 |
+
for key in index_dict:
|
34 |
+
if index==key:
|
35 |
+
|
36 |
+
qdrant_local_path = index_dict[key]
|
37 |
+
qdrant_client = QdrantClient(path=qdrant_local_path)
|
38 |
+
collection_name = key
|
39 |
+
vector_size = 1024
|
40 |
+
qdrant_vector_store = QdrantVectorStore(client=qdrant_client, collection_name=collection_name)
|
41 |
+
storage_context = StorageContext.from_defaults(vector_store=qdrant_vector_store)
|
42 |
+
vector_index = VectorStoreIndex.from_vector_store(vector_store=qdrant_vector_store, embed_model=embedding_function)
|
43 |
+
|
44 |
+
return vector_index
|
45 |
+
|
custom_prompt.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e4e5c69cc2b4f1a0f08a60400f1938e2065f588852a3413b51be84beef7f2c09
|
3 |
+
size 3547
|
index_dict.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f25c1f2ade45f3d6505ce7d14de2a53a78fa15ea2391403914acc74083a76ee8
|
3 |
+
size 891
|
prompt_engg.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:86f74a37f3395ab2dcb338817229a514fb088a73ef19f2a5375c62fe26b3eef0
|
3 |
+
size 3387
|
qdrant/a_lecture_upon_the_shadow/collection/A Lecture Upon The Shadow/storage.sqlite
ADDED
Binary file (73.7 kB). View file
|
|
qdrant/a_lecture_upon_the_shadow/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"A Lecture Upon The Shadow": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/a_wedding_in_brownsville/collection/A Wedding In Brownsville/storage.sqlite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f8679d7531ef82317bdd021eca23e36c786f7b37449d87fd7284bb87fac3cc3b
|
3 |
+
size 249856
|
qdrant/a_wedding_in_brownsville/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"A Wedding In Brownsville": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/blood/collection/Blood/storage.sqlite
ADDED
Binary file (86 kB). View file
|
|
qdrant/blood/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"Blood": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/broken_images/collection/Broken Images/storage.sqlite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6b05cde8cb5b216ba57c4d90bc9fce675267a067589937e5b578cd71f2277e04
|
3 |
+
size 192512
|
qdrant/broken_images/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"Broken Images": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/chandalika/collection/Chandalika/storage.sqlite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3095aba29f6f65cdd96fb1b7242c804c5fd731e435e8cedcb8204a8ef339ce83
|
3 |
+
size 278528
|
qdrant/chandalika/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"Chandalika": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/eveline/collection/Eveline/storage.sqlite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:10fcd809f3656f1541c21e8c1746fea89c65e8aa67faceabd8e028d58f4c48bf
|
3 |
+
size 126976
|
qdrant/eveline/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"Eveline": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/film_making/collection/Flim Making/storage.sqlite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d2568eae30c5faa4b19c259958638603cacc0866d4ebb64cd4592e321b0ed9e2
|
3 |
+
size 217088
|
qdrant/film_making/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"Flim Making": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/freedom/collection/Freedom/storage.sqlite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7502afa6ac1315c1a4c55bacc7c69ecdf2b44df82cd02007d13d783c22824057
|
3 |
+
size 245760
|
qdrant/freedom/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"Freedom": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/i_sell_my_dreams/collection/I Sell My Dreams/storage.sqlite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:aeef7afad2458147d6657b0aec74455be1277e42f722491c408615024929b30d
|
3 |
+
size 155648
|
qdrant/i_sell_my_dreams/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"I Sell My Dreams": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/kubla_khan/collection/Kubla Khan/storage.sqlite
ADDED
Binary file (86 kB). View file
|
|
qdrant/kubla_khan/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"Kubla Khan": {"vectors": {"size": 1024, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null, "datatype": null, "multivector_config": null}, "shard_number": null, "sharding_method": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null, "sparse_vectors": null, "strict_mode_config": null}}, "aliases": {}}
|
qdrant/on_science_fiction/collection/On Science Fiction/storage.sqlite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d860e2d76c3939b7234fa0fd4a18181722af218cc6d6afef54dede3ac5ab08fe
|
3 |
+
size 167936
|