Update main.py
Browse files
main.py
CHANGED
@@ -49,7 +49,7 @@ async def VectorDatabase(categorie):
|
|
49 |
async def Retriever(categorie):
|
50 |
vectorstore = await VectorDatabase(categorie)
|
51 |
if categorie == "videosTC":
|
52 |
-
retriever = vectorstore.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": .7, "k":
|
53 |
return retriever
|
54 |
|
55 |
@cl.step(type="embedding")
|
@@ -63,17 +63,18 @@ async def Search(input, categorie):
|
|
63 |
count = 0
|
64 |
countOffres = 0
|
65 |
if categorie == "videosTC":
|
66 |
-
search = vectorstore.similarity_search(input,k=50, filter={"title": {"$eq": "videos-
|
67 |
for i in range(0,len(search)):
|
68 |
-
if count <=
|
69 |
count = count + 1
|
70 |
timeSeq = search[i].metadata["time"]
|
71 |
timeSeqRound = round(timeSeq)
|
72 |
time = timedelta(seconds=timeSeqRound)
|
73 |
sources_text = sources_text + '<div class="gridvid"><a target="_blank" title="' + search[i].metadata['titre'] + ' : ...' + search[i].page_content + '" href="' + search[i].metadata['video'] + '#start=' + str(timeSeq) + '"><img src="' + search[i].metadata['image'] + '" width="100%" alt="' + search[i].metadata['titre'] + ' : ...' + search[i].page_content + '"/><p>🕓 ' + str(time) + ' : ...' + search[i].page_content + ' : ' + search[i].metadata['titre'] + '</p></a></div>'
|
|
|
74 |
verbatim_text = verbatim_text + "<p style='font-size:0.8rem'>" + str(count) + ". " + search[i].metadata['titre'] + "</p><p style='font-size:0.8rem'>🕓 "+ str(time) + " : " + search[i].page_content + "</p>"
|
75 |
|
76 |
-
results = [sources_text, verbatim_text,
|
77 |
return results
|
78 |
|
79 |
@cl.set_chat_profiles
|
@@ -170,18 +171,18 @@ async def on_message(message: cl.Message):
|
|
170 |
search = await Search(message.content, "videosTC")
|
171 |
|
172 |
sources = [
|
173 |
-
cl.Text(name="Sources", content=search[0], display="inline")
|
174 |
]
|
175 |
await cl.Message(
|
176 |
-
content="
|
177 |
elements=sources,
|
178 |
).send()
|
179 |
if search[2]:
|
180 |
sourcesOffres = [
|
181 |
-
cl.Text(name="
|
182 |
]
|
183 |
await cl.Message(
|
184 |
-
content="
|
185 |
elements=sourcesOffres,
|
186 |
).send()
|
187 |
verbatim = [
|
|
|
49 |
async def Retriever(categorie):
|
50 |
vectorstore = await VectorDatabase(categorie)
|
51 |
if categorie == "videosTC":
|
52 |
+
retriever = vectorstore.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": .7, "k": 250,"filter": {"title": {"$eq": "videos-table-rondeia"}, "time": {"$gte": 1320}}})
|
53 |
return retriever
|
54 |
|
55 |
@cl.step(type="embedding")
|
|
|
63 |
count = 0
|
64 |
countOffres = 0
|
65 |
if categorie == "videosTC":
|
66 |
+
search = vectorstore.similarity_search(input,k=50, filter={"title": {"$eq": "videos-table-rondeia"}, "time": {"$gte": 1320}})
|
67 |
for i in range(0,len(search)):
|
68 |
+
if count <= 23:
|
69 |
count = count + 1
|
70 |
timeSeq = search[i].metadata["time"]
|
71 |
timeSeqRound = round(timeSeq)
|
72 |
time = timedelta(seconds=timeSeqRound)
|
73 |
sources_text = sources_text + '<div class="gridvid"><a target="_blank" title="' + search[i].metadata['titre'] + ' : ...' + search[i].page_content + '" href="' + search[i].metadata['video'] + '#start=' + str(timeSeq) + '"><img src="' + search[i].metadata['image'] + '" width="100%" alt="' + search[i].metadata['titre'] + ' : ...' + search[i].page_content + '"/><p>🕓 ' + str(time) + ' : ...' + search[i].page_content + ' : ' + search[i].metadata['titre'] + '</p></a></div>'
|
74 |
+
sources_audio = sources_text + '<div class="gridvid"><a target="_blank" title="' + search[i].metadata['titre'] + ' : ...' + search[i].page_content + '" href="' + search[i].metadata['Audio'] + '#start=' + str(timeSeq) + '"><img src="' + search[i].metadata['thumb'] + '" width="100%" alt="' + search[i].metadata['titre'] + ' : ...' + search[i].page_content + '"/><p>🕓 ' + str(time) + ' : ...' + search[i].page_content + ' : ' + search[i].metadata['titre'] + '</p></a></div>'
|
75 |
verbatim_text = verbatim_text + "<p style='font-size:0.8rem'>" + str(count) + ". " + search[i].metadata['titre'] + "</p><p style='font-size:0.8rem'>🕓 "+ str(time) + " : " + search[i].page_content + "</p>"
|
76 |
|
77 |
+
results = [sources_text, verbatim_text, sources_audio]
|
78 |
return results
|
79 |
|
80 |
@cl.set_chat_profiles
|
|
|
171 |
search = await Search(message.content, "videosTC")
|
172 |
|
173 |
sources = [
|
174 |
+
cl.Text(name="Sources vidéo", content=search[0], display="inline")
|
175 |
]
|
176 |
await cl.Message(
|
177 |
+
content="Vidéos : ",
|
178 |
elements=sources,
|
179 |
).send()
|
180 |
if search[2]:
|
181 |
sourcesOffres = [
|
182 |
+
cl.Text(name="Sources audio", content=search[2], display="inline")
|
183 |
]
|
184 |
await cl.Message(
|
185 |
+
content="Audio : ",
|
186 |
elements=sourcesOffres,
|
187 |
).send()
|
188 |
verbatim = [
|