Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -88,4 +88,49 @@ def card(thumbnail: str, title: str, urls: list, contexts: list, starts: list, e
|
|
88 |
{html_text}
|
89 |
<br><br>
|
90 |
"""
|
91 |
-
return st.markdown(html, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
{html_text}
|
89 |
<br><br>
|
90 |
"""
|
91 |
+
return st.markdown(html, unsafe_allow_html=True)
|
92 |
+
|
93 |
+
query = st.text_input("Search!", "")
|
94 |
+
|
95 |
+
if query != "":
|
96 |
+
channels = [channel_map[name] for name in channel_options]
|
97 |
+
print(f"query: {query}")
|
98 |
+
matches = make_query(
|
99 |
+
query, retriever, top_k=5,
|
100 |
+
filter={
|
101 |
+
'channel_id': {'$in': channels}
|
102 |
+
}
|
103 |
+
)
|
104 |
+
|
105 |
+
results = {}
|
106 |
+
order = []
|
107 |
+
for context in matches:
|
108 |
+
video_id = context['metadata']['url'].split('/')[-1]
|
109 |
+
if video_id not in results:
|
110 |
+
results[video_id] = {
|
111 |
+
'title': context['metadata']['title'],
|
112 |
+
'urls': [f"{context['metadata']['url']}?t={int(context['metadata']['start'])}"],
|
113 |
+
'contexts': [context['metadata']['text']],
|
114 |
+
'starts': [int(context['metadata']['start'])],
|
115 |
+
'ends': [int(context['metadata']['end'])]
|
116 |
+
}
|
117 |
+
order.append(video_id)
|
118 |
+
else:
|
119 |
+
results[video_id]['urls'].append(
|
120 |
+
f"{context['metadata']['url']}?t={int(context['metadata']['start'])}"
|
121 |
+
)
|
122 |
+
results[video_id]['contexts'].append(
|
123 |
+
context['metadata']['text']
|
124 |
+
)
|
125 |
+
results[video_id]['starts'].append(int(context['metadata']['start']))
|
126 |
+
results[video_id]['ends'].append(int(context['metadata']['end']))
|
127 |
+
# now display cards
|
128 |
+
for video_id in order:
|
129 |
+
card(
|
130 |
+
thumbnail=f"https://img.youtube.com/vi/{video_id}/maxresdefault.jpg",
|
131 |
+
title=results[video_id]['title'],
|
132 |
+
urls=results[video_id]['urls'],
|
133 |
+
contexts=results[video_id]['contexts'],
|
134 |
+
starts=results[video_id]['starts'],
|
135 |
+
ends=results[video_id]['ends']
|
136 |
+
)
|