marcellopoliti commited on
Commit
21cef57
1 Parent(s): 8e018ae

refactor pages

Browse files
pages/create_knowledge_box.py DELETED
@@ -1,44 +0,0 @@
1
- import streamlit as st
2
- from app import client, default_embedding_function, show_sidebar
3
- import pandas as pd
4
- from generate_kb import generate_knowledge_box_from_url
5
- from utils import get_chroma_client
6
-
7
- # Title of the app
8
- st.title("Create a knowledge box from CSV file")
9
- show_sidebar()
10
-
11
- # File uploader widget
12
- uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
13
- df = None
14
-
15
- collection_name = st.text_input(label="empy collection name")
16
- if st.button("create empty knowledge box"):
17
- client = get_chroma_client()
18
- collection = client.create_collection(name=collection_name)
19
- st.success("collection created")
20
- st.write(collection)
21
-
22
-
23
- if uploaded_file is not None:
24
- try:
25
- df = pd.read_csv(uploaded_file)
26
- st.write("DataFrame:")
27
- st.write(df)
28
- except Exception as e:
29
- st.error(str(e))
30
-
31
-
32
- if uploaded_file is not None:
33
- st.text("dont use spaces but underscores _ in your new name")
34
- kb_name = st.text_input(label="new knowledge base name")
35
- if st.button("Generate new knowledge box"):
36
- urls = df.values.tolist()
37
- res = generate_knowledge_box_from_url(
38
- client=client,
39
- urls=urls,
40
- kb_name=kb_name,
41
- embedding_fct=default_embedding_function,
42
- chunk_size=2_000,
43
- )
44
- st.json(res)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/{delete_knowledge_box⚠️.py → create_or_delete_kb.py} RENAMED
@@ -1,17 +1,30 @@
1
  import streamlit as st
2
  from retrieve_kb import get_current_knowledge_bases
3
  from app import client, show_sidebar
 
4
 
5
 
6
  st.title("Delete knowledge Base ☠️")
7
  show_sidebar()
8
 
9
- st.title("Get knowledge boxes")
10
- if st.button("Get current knowledge bases"):
11
- kbs = get_current_knowledge_bases(client=client)
12
- st.json(kbs)
13
 
14
- collection_name = st.text_input(label="collection name")
 
 
15
  if st.button("Delete Forever"):
16
  client.delete_collection(collection_name)
17
  st.success("Deleted")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from retrieve_kb import get_current_knowledge_bases
3
  from app import client, show_sidebar
4
+ from utils import get_chroma_client
5
 
6
 
7
  st.title("Delete knowledge Base ☠️")
8
  show_sidebar()
9
 
 
 
 
 
10
 
11
+ kbs = get_current_knowledge_bases(client=client)
12
+ kbs = (kb.name for kb in kbs)
13
+ collection_name = st.selectbox("Select knowledge box to delete", kbs)
14
  if st.button("Delete Forever"):
15
  client.delete_collection(collection_name)
16
  st.success("Deleted")
17
+ st.experimental_rerun()
18
+
19
+
20
+ # Title of the app
21
+ st.title("Create a knowledge box")
22
+ show_sidebar()
23
+
24
+ collection_name = st.text_input(label="empy collection name")
25
+ if st.button("create empty knowledge box"):
26
+ client = get_chroma_client()
27
+ collection = client.create_collection(name=collection_name)
28
+ st.success("collection created")
29
+ st.write(collection)
30
+ st.experimental_rerun()
pages/manage_knowledge_box.py CHANGED
@@ -179,7 +179,7 @@ else:
179
 
180
 
181
  tab1, tab2, tab3, tab4, tab5 = st.tabs(
182
- ["Remove", "Add URL", "Add CSV", "Add PDF", "Add Youtube"]
183
  )
184
 
185
  # remove stuff tab
@@ -228,19 +228,6 @@ with tab2:
228
  with tab3:
229
  list_manager()
230
 
231
- # st.header("Add csv to existing collection")
232
- # uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
233
- # df = None
234
- # if uploaded_file is not None:
235
- # try:
236
- # new_df = pd.read_csv(uploaded_file)
237
- # st.write("DataFrame:")
238
- # st.write(new_df)
239
- # except Exception as e:
240
- # st.error(str(e))
241
- # if st.button("add csv urls to collection"):
242
- # urls = new_df.values.tolist()
243
- # st.write(urls)
244
  if st.button("add csv urls to collection"):
245
  res = add_links_to_knowledge_base(
246
  client=client, kb_name=collection_name, urls=st.session_state["url_list"]
@@ -251,6 +238,10 @@ with tab3:
251
  # Add PDF
252
  with tab4:
253
  st.header("Add pdf to existing collection")
 
 
 
 
254
  uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
255
  pdf_optional_link = st.text_input(
256
  "Insert a URL link you want to associate with the pdf"
@@ -286,12 +277,13 @@ with tab5:
286
 
287
  video_url = st.text_input("Youtube video url")
288
  st.text(
289
- "Aggiungere il video puo impiegare un bel pò. Avvia e vatti a fare una canna"
290
  )
291
  if st.button("Add video"):
292
  # Create a temporary file
293
  # Write the uploaded PDF to the temporary file
294
  try:
 
295
  download_and_transcribe_youtube(video_url)
296
  st.success("Video Added")
297
  except Exception as e:
 
179
 
180
 
181
  tab1, tab2, tab3, tab4, tab5 = st.tabs(
182
+ ["Remove", "Add URL", "Multiple URL", "Add PDF", "Add Youtube"]
183
  )
184
 
185
  # remove stuff tab
 
228
  with tab3:
229
  list_manager()
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  if st.button("add csv urls to collection"):
232
  res = add_links_to_knowledge_base(
233
  client=client, kb_name=collection_name, urls=st.session_state["url_list"]
 
238
  # Add PDF
239
  with tab4:
240
  st.header("Add pdf to existing collection")
241
+ st.write(
242
+ "Trick: if you want to add a Notion page, \
243
+ download the page as pdf, and load the pdf here together with the notion url"
244
+ )
245
  uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
246
  pdf_optional_link = st.text_input(
247
  "Insert a URL link you want to associate with the pdf"
 
277
 
278
  video_url = st.text_input("Youtube video url")
279
  st.text(
280
+ "Aggiungere il video puo impiegare un bel pò. Avvia e vatti a fare una sigaretta"
281
  )
282
  if st.button("Add video"):
283
  # Create a temporary file
284
  # Write the uploaded PDF to the temporary file
285
  try:
286
+ st.video(video_url)
287
  download_and_transcribe_youtube(video_url)
288
  st.success("Video Added")
289
  except Exception as e: