michaelgohn commited on
Commit
04ab5b4
·
1 Parent(s): 2407d83

Reorganized the notebook and context upload sections, and changed some button colors.

Browse files
Files changed (1) hide show
  1. app.py +62 -55
app.py CHANGED
@@ -84,8 +84,8 @@ CUSTOM_CSS = """
84
  .hero-title { font-size: 2rem; font-weight: 700; color: #1e293b; margin: 0 0 8px 0; }
85
  .hero-sub { font-size: 1rem; color: #64748b; margin: 0; line-height: 1.5; }
86
 
87
- .section-card { padding: 24px; border-radius: 16px; background: #f8fafc; margin-bottom: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
88
- .notebook-card { padding: 14px 20px; border-radius: 12px; background: #fff; margin-bottom: 8px; border: 1px solid #e2e8f0; display: flex; align-items: center; gap: 12px; transition: background 0.15s ease; }
89
  .notebook-card:hover { background: #f8fafc; }
90
 
91
  .section-title { font-size: 1.125rem; font-weight: 600; color: #1e293b; margin: 0 0 16px 0; }
@@ -93,7 +93,7 @@ CUSTOM_CSS = """
93
  .section-row .gr-textbox { flex: 1 !important; }
94
  .section-row .gr-button { border-radius: 10px !important; padding: 10px 20px !important; }
95
 
96
- .status { font-size: 0.875rem; color: #64748b; margin-top: 16px; padding: 12px 16px; background: #f1f5f9; border-radius: 12px; }
97
 
98
  @media (prefers-color-scheme: dark) {
99
  .hero-title { color: #f1f5f9 !important; }
@@ -111,6 +111,11 @@ CUSTOM_CSS = """
111
  .dark .notebook-card { background: #334155 !important; border-color: #475569; }
112
  .dark .notebook-card:hover { background: #475569 !important; }
113
  .dark .status { color: #94a3b8 !important; background: #334155 !important; }
 
 
 
 
 
114
  """
115
 
116
  def _user_id(profile: gr.OAuthProfile | None) -> str | None:
@@ -612,7 +617,7 @@ with gr.Blocks(
612
  ) as demo:
613
  with gr.Row(elem_classes=["header-bar"]):
614
  gr.Markdown("### 📓 NotebookLM Clone")
615
- login_btn = gr.LoginButton(value="🤗 Login with Hugging Face", size="lg")
616
 
617
  with gr.Row(visible=False) as auth_info_row:
618
  auth_text = gr.Markdown("", elem_id="auth-text")
@@ -642,6 +647,51 @@ with gr.Blocks(
642
  )
643
  create_btn = gr.Button("Create", variant="primary", size="sm")
644
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645
  with gr.Group(elem_classes=["section-card"]):
646
  gr.Markdown("**Sources**", elem_classes=["section-title"])
647
  gr.Markdown("*Upload PDFs, ingest URLs, or add text to your selected notebook*")
@@ -661,7 +711,7 @@ with gr.Blocks(
661
  scale=3,
662
  allow_custom_value=False,
663
  )
664
- remove_pdf_btn = gr.Button("Remove selected PDF", variant="stop", scale=1)
665
  with gr.Row(elem_classes=["section-row"]):
666
  url_txt = gr.Textbox(
667
  label="Ingest web URL",
@@ -669,58 +719,15 @@ with gr.Blocks(
669
  value="",
670
  scale=3,
671
  )
672
- ingest_url_btn = gr.Button("Ingest URL", variant="primary", scale=1)
673
- remove_url_btn = gr.Button("Delete URL", variant="stop", scale=1)
674
-
675
- gr.HTML("<br>")
676
- gr.Markdown("**Your Notebooks**", elem_classes=["section-title"])
677
- gr.Markdown("*Selected notebook is used for chat and ingestion*", elem_id="sub-hint")
678
- gr.HTML("<br>")
679
-
680
- status = gr.Markdown("Sign in with Hugging Face to manage notebooks.", elem_classes=["status"])
681
-
682
- @gr.render(inputs=[nb_state])
683
- def render_notebooks(state):
684
- if not state:
685
- gr.Markdown("No notebooks yet. Create one to get started.")
686
- else:
687
- for i, (nb_id, name) in enumerate(state):
688
- idx = i
689
- with gr.Row(elem_classes=["notebook-card"]):
690
- name_txt = gr.Textbox(value=name, show_label=False, scale=4, min_width=240, key=f"nb-name-{nb_id}")
691
- select_btn = gr.Button("Select", variant="primary", scale=1, min_width=80, size="sm")
692
- rename_btn = gr.Button("Rename", variant="secondary", scale=1, min_width=80, size="sm")
693
- delete_btn = gr.Button("Delete", variant="secondary", scale=1, min_width=80, size="sm")
694
-
695
- def on_select(nb_id=nb_id):
696
- return nb_id
697
-
698
- def on_select_status():
699
- return "Selected notebook updated. Use this for chat/ingestion."
700
-
701
- select_btn.click(
702
- on_select,
703
- inputs=None,
704
- outputs=[selected_notebook_id],
705
- ).then(on_select_status, None, [status]).then(_list_uploaded_pdfs, inputs=[selected_notebook_id], outputs=[uploaded_pdf_dd])
706
-
707
- rename_btn.click(
708
- _safe_rename,
709
- inputs=[gr.State(idx), name_txt, nb_state, selected_notebook_id],
710
- outputs=[nb_state, selected_notebook_id, status],
711
- api_name=False,
712
- )
713
-
714
- delete_btn.click(
715
- _safe_delete,
716
- inputs=[gr.State(idx), nb_state, selected_notebook_id],
717
- outputs=[nb_state, selected_notebook_id, status],
718
- api_name=False,
719
- ).then(_list_uploaded_pdfs, inputs=[selected_notebook_id], outputs=[uploaded_pdf_dd])
720
 
721
- gr.HTML("<br>")
722
 
723
- with gr.Group(elem_classes=["section-card"]):
 
 
 
724
  gr.Markdown("**Add Text**", elem_classes=["section-title"])
725
  gr.Markdown("*Select a notebook above, then paste or type your text*")
726
  with gr.Row():
 
84
  .hero-title { font-size: 2rem; font-weight: 700; color: #1e293b; margin: 0 0 8px 0; }
85
  .hero-sub { font-size: 1rem; color: #64748b; margin: 0; line-height: 1.5; }
86
 
87
+ .section-card { padding: 24px; border-radius: 16px; background: #f8fafc; margin: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
88
+ .notebook-card { padding: 14px 20px; border-radius: 12px; background: #fff; margin: 8px; border: 1px solid #e2e8f0; display: flex; align-items: center; gap: 12px; transition: background 0.15s ease; }
89
  .notebook-card:hover { background: #f8fafc; }
90
 
91
  .section-title { font-size: 1.125rem; font-weight: 600; color: #1e293b; margin: 0 0 16px 0; }
 
93
  .section-row .gr-textbox { flex: 1 !important; }
94
  .section-row .gr-button { border-radius: 10px !important; padding: 10px 20px !important; }
95
 
96
+ .status { font-size: 0.875rem; color: #64748b; margin: 16px; padding: 12px 16px; background: #f1f5f9; border-radius: 12px; }
97
 
98
  @media (prefers-color-scheme: dark) {
99
  .hero-title { color: #f1f5f9 !important; }
 
111
  .dark .notebook-card { background: #334155 !important; border-color: #475569; }
112
  .dark .notebook-card:hover { background: #475569 !important; }
113
  .dark .status { color: #94a3b8 !important; background: #334155 !important; }
114
+
115
+ #delete-btn { border-radius: 16px; background: #FF0000; }
116
+ #rename-btn { border-radius: 16px; background: #008000; }
117
+ #select-btn { border-radius: 16px; }
118
+ #ingest-url-btn { border-radius: 16px; }
119
  """
120
 
121
  def _user_id(profile: gr.OAuthProfile | None) -> str | None:
 
617
  ) as demo:
618
  with gr.Row(elem_classes=["header-bar"]):
619
  gr.Markdown("### 📓 NotebookLM Clone")
620
+ login_btn = gr.LoginButton(value="🤗 Login with Hugging Face", size="lg", elem_id=["lgn-btn"])
621
 
622
  with gr.Row(visible=False) as auth_info_row:
623
  auth_text = gr.Markdown("", elem_id="auth-text")
 
647
  )
648
  create_btn = gr.Button("Create", variant="primary", size="sm")
649
 
650
+ with gr.Group(elem_classes=["section-card"]):
651
+ gr.HTML("<br>")
652
+ gr.Markdown("**Your Notebooks**", elem_classes=["section-title"])
653
+ notebook_status = gr.Markdown("Sign in with Hugging Face to manage notebooks.", elem_classes=["status"])
654
+ gr.HTML("<br>")
655
+
656
+ @gr.render(inputs=[nb_state])
657
+ def render_notebooks(state):
658
+ if not state:
659
+ gr.Markdown("No notebooks yet. Create one to get started.")
660
+ else:
661
+ for i, (nb_id, name) in enumerate(state):
662
+ idx = i
663
+ with gr.Row(elem_classes=["notebook-card"]):
664
+ name_txt = gr.Textbox(value=name, show_label=False, scale=4, min_width=240, key=f"nb-name-{nb_id}")
665
+ select_btn = gr.Button("Select", variant="primary", scale=1, min_width=80, size="sm", elem_id="select-btn")
666
+ rename_btn = gr.Button("Rename", variant="secondary", scale=1, min_width=80, size="sm", elem_id="rename-btn")
667
+ delete_btn = gr.Button("Delete", variant="secondary", scale=1, min_width=80, size="sm", elem_id="delete-btn")
668
+
669
+ def on_select(nb_id=nb_id, name_txt=name_txt):
670
+ return nb_id, name_txt
671
+
672
+ def on_select_status(name_txt=name_txt):
673
+ return f"Selected notebook updated. Use this for chat/ingestion.\n**Notebook: {name_txt}**"
674
+
675
+ select_btn.click(
676
+ on_select,
677
+ inputs=None,
678
+ outputs=[selected_notebook_id, name_txt],
679
+ ).then(on_select_status, inputs=[name_txt], outputs=[notebook_status]).then(_list_uploaded_pdfs, inputs=[selected_notebook_id], outputs=[uploaded_pdf_dd])
680
+
681
+ rename_btn.click(
682
+ _safe_rename,
683
+ inputs=[gr.State(idx), name_txt, nb_state, selected_notebook_id],
684
+ outputs=[nb_state, selected_notebook_id, notebook_status],
685
+ api_name=False,
686
+ )
687
+
688
+ delete_btn.click(
689
+ _safe_delete,
690
+ inputs=[gr.State(idx), nb_state, selected_notebook_id],
691
+ outputs=[nb_state, selected_notebook_id, notebook_status],
692
+ api_name=False,
693
+ ).then(_list_uploaded_pdfs, inputs=[selected_notebook_id], outputs=[uploaded_pdf_dd])
694
+
695
  with gr.Group(elem_classes=["section-card"]):
696
  gr.Markdown("**Sources**", elem_classes=["section-title"])
697
  gr.Markdown("*Upload PDFs, ingest URLs, or add text to your selected notebook*")
 
711
  scale=3,
712
  allow_custom_value=False,
713
  )
714
+ remove_pdf_btn = gr.Button("Remove selected PDF", variant="stop", scale=1, elem_id="delete-btn")
715
  with gr.Row(elem_classes=["section-row"]):
716
  url_txt = gr.Textbox(
717
  label="Ingest web URL",
 
719
  value="",
720
  scale=3,
721
  )
722
+ ingest_url_btn = gr.Button("Ingest URL", variant="primary", scale=1, elem_id="ingest-url-btn")
723
+ remove_url_btn = gr.Button("Delete URL", variant="stop", scale=1, elem_id="delete-btn")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
724
 
725
+ status = gr.Markdown("Sign in with Hugging Face to upload context material.", elem_classes=["status"])
726
 
727
+ gr.HTML("<br>")
728
+ gr.HTML("<br>")
729
+ gr.HTML("<br>")
730
+
731
  gr.Markdown("**Add Text**", elem_classes=["section-title"])
732
  gr.Markdown("*Select a notebook above, then paste or type your text*")
733
  with gr.Row():