mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-05-01 21:00:43 +00:00
improve citations and add object page
This commit is contained in:
parent
35c68dff11
commit
3ea4e41a78
14 changed files with 362 additions and 138 deletions
11
pages/components/__init__.py
Normal file
11
pages/components/__init__.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from pages.components.note_panel import note_panel
|
||||
from pages.components.source_embedding_panel import source_embedding_panel
|
||||
from pages.components.source_insight import source_insight_panel
|
||||
from pages.components.source_panel import source_panel
|
||||
|
||||
__all__ = [
|
||||
"note_panel",
|
||||
"source_embedding_panel",
|
||||
"source_insight_panel",
|
||||
"source_panel",
|
||||
]
|
||||
30
pages/components/note_panel.py
Normal file
30
pages/components/note_panel.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import streamlit as st
|
||||
from loguru import logger
|
||||
from streamlit_monaco import st_monaco # type: ignore
|
||||
|
||||
from open_notebook.domain.notebook import Note
|
||||
|
||||
|
||||
def note_panel(note_id, notebook_id=None):
|
||||
note: Note = Note.get(note_id)
|
||||
if not note:
|
||||
raise ValueError(f"Note not fonud {note_id}")
|
||||
t_preview, t_edit = st.tabs(["Preview", "Edit"])
|
||||
with t_preview:
|
||||
st.subheader(note.title)
|
||||
st.markdown(note.content)
|
||||
with t_edit:
|
||||
note.title = st.text_input("Title", value=note.title)
|
||||
note.content = st_monaco(
|
||||
value=note.content, height="600px", language="markdown"
|
||||
)
|
||||
if st.button("Save", key=f"pn_edit_note_{note.id or 'new'}"):
|
||||
logger.debug("Editing note")
|
||||
note.save()
|
||||
if not note.id and notebook_id:
|
||||
note.add_to_notebook(notebook_id)
|
||||
st.rerun()
|
||||
if st.button("Delete", type="primary", key=f"delete_note_{note.id or 'new'}"):
|
||||
logger.debug("Deleting note")
|
||||
note.delete()
|
||||
st.rerun()
|
||||
17
pages/components/source_embedding_panel.py
Normal file
17
pages/components/source_embedding_panel.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import streamlit as st
|
||||
|
||||
from open_notebook.domain.notebook import SourceEmbedding
|
||||
|
||||
|
||||
def source_embedding_panel(source_embedding_id):
|
||||
si: SourceEmbedding = SourceEmbedding.get(source_embedding_id)
|
||||
if not si:
|
||||
raise ValueError(f"Embedding not found {source_embedding_id}")
|
||||
with st.container(border=True):
|
||||
url = f"Navigator?object_id={si.source.id}"
|
||||
st.markdown("**Original Source**")
|
||||
st.markdown(f"{si.source.title} [link](%s)" % url)
|
||||
st.markdown(si.content)
|
||||
if st.button("Delete", type="primary", key=f"delete_embedding_{si.id or 'new'}"):
|
||||
si.delete()
|
||||
st.rerun()
|
||||
18
pages/components/source_insight.py
Normal file
18
pages/components/source_insight.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import streamlit as st
|
||||
|
||||
from open_notebook.domain.notebook import SourceInsight
|
||||
|
||||
|
||||
def source_insight_panel(source, notebook_id=None):
|
||||
si: SourceInsight = SourceInsight.get(source)
|
||||
if not si:
|
||||
raise ValueError(f"insight not found {source}")
|
||||
st.subheader(si.insight_type)
|
||||
with st.container(border=True):
|
||||
url = f"Navigator?object_id={si.source.id}"
|
||||
st.markdown("**Original Source**")
|
||||
st.markdown(f"{si.source.title} [link](%s)" % url)
|
||||
st.markdown(si.content)
|
||||
if st.button("Delete", type="primary", key=f"delete_insight_{si.id or 'new'}"):
|
||||
si.delete()
|
||||
st.rerun()
|
||||
84
pages/components/source_panel.py
Normal file
84
pages/components/source_panel.py
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
import streamlit as st
|
||||
import streamlit_scrollable_textbox as stx # type: ignore
|
||||
import yaml
|
||||
from humanize import naturaltime
|
||||
|
||||
from open_notebook.domain.notebook import Source
|
||||
from open_notebook.utils import surreal_clean
|
||||
from pages.stream_app.utils import run_patterns
|
||||
|
||||
|
||||
def source_panel(source_id: str, modal=False):
|
||||
source: Source = Source.get(source_id)
|
||||
if not source:
|
||||
raise ValueError(f"Source not found: {source_id}")
|
||||
|
||||
current_title = source.title if source.title else "No Title"
|
||||
source.title = st.text_input("Title", value=current_title)
|
||||
if source.title != current_title:
|
||||
st.toast("Saved new Title")
|
||||
source.save()
|
||||
|
||||
process_tab, source_tab = st.tabs(["Process", "Source"])
|
||||
with process_tab:
|
||||
c1, c2 = st.columns([3, 1])
|
||||
with c1:
|
||||
title = st.empty()
|
||||
if source.title:
|
||||
title.subheader(source.title)
|
||||
if source.asset and source.asset.url:
|
||||
from_src = f"from URL: {source.asset.url}"
|
||||
elif source.asset and source.asset.file_path:
|
||||
from_src = f"from file: {source.asset.file_path}"
|
||||
else:
|
||||
from_src = "from text"
|
||||
st.caption(f"Created {naturaltime(source.created)}, {from_src}")
|
||||
for insight in source.insights:
|
||||
with st.expander(f"**{insight.insight_type}**"):
|
||||
st.markdown(insight.content)
|
||||
if st.button(
|
||||
"Delete", type="primary", key=f"delete_insight_{insight.id}"
|
||||
):
|
||||
insight.delete()
|
||||
st.rerun(scope="fragment" if modal else "app")
|
||||
|
||||
with c2:
|
||||
with open("transformations.yaml", "r") as file:
|
||||
transformations = yaml.safe_load(file)
|
||||
for transformation in transformations["source_insights"]:
|
||||
if st.button(
|
||||
transformation["name"], help=transformation["description"]
|
||||
):
|
||||
result = run_patterns(
|
||||
source.full_text, transformation["patterns"]
|
||||
)
|
||||
source.add_insight(
|
||||
transformation["insight_type"], surreal_clean(result)
|
||||
)
|
||||
st.rerun(scope="fragment" if modal else "app")
|
||||
|
||||
if st.button(
|
||||
"Embed vectors",
|
||||
icon="🦾",
|
||||
disabled=source.embedded_chunks > 0,
|
||||
help="This will generate your embedding vectors on the database for powerful search capabilities",
|
||||
):
|
||||
source.vectorize()
|
||||
st.success("Embedding complete")
|
||||
|
||||
chk_delete = st.checkbox(
|
||||
"🗑️ Delete source", key=f"delete_source_{source.id}", value=False
|
||||
)
|
||||
if chk_delete:
|
||||
st.warning(
|
||||
"Source will be deleted with all its insights and embeddings"
|
||||
)
|
||||
if st.button(
|
||||
"Delete", type="primary", key=f"bt_delete_source_{source.id}"
|
||||
):
|
||||
source.delete()
|
||||
st.rerun()
|
||||
|
||||
with source_tab:
|
||||
st.subheader("Content")
|
||||
stx.scrollableTextbox(source.full_text, height=300)
|
||||
Loading…
Add table
Add a link
Reference in a new issue