diff --git a/App_Function_Libraries/DB/DB_Manager.py b/App_Function_Libraries/DB/DB_Manager.py
index 2bf5c90a8..13c3cb15d 100644
--- a/App_Function_Libraries/DB/DB_Manager.py
+++ b/App_Function_Libraries/DB/DB_Manager.py
@@ -16,8 +16,8 @@
from App_Function_Libraries.DB.Prompts_DB import list_prompts as sqlite_list_prompts, \
fetch_prompt_details as sqlite_fetch_prompt_details, add_prompt as sqlite_add_prompt, \
search_prompts as sqlite_search_prompts, add_or_update_prompt as sqlite_add_or_update_prompt, \
- load_prompt_details as sqlite_load_prompt_details, load_preset_prompts as sqlite_load_preset_prompts, \
- insert_prompt_to_db as sqlite_insert_prompt_to_db, delete_prompt as sqlite_delete_prompt
+ load_prompt_details as sqlite_load_prompt_details, insert_prompt_to_db as sqlite_insert_prompt_to_db, \
+ delete_prompt as sqlite_delete_prompt
from App_Function_Libraries.DB.SQLite_DB import (
update_media_content as sqlite_update_media_content,
search_and_display as sqlite_search_and_display,
@@ -501,13 +501,6 @@ def load_prompt_details(*args, **kwargs):
# Implement Elasticsearch version
raise NotImplementedError("Elasticsearch version of add_media_with_keywords not yet implemented")
-def load_preset_prompts(*args, **kwargs):
- if db_type == 'sqlite':
- return sqlite_load_preset_prompts()
- elif db_type == 'elasticsearch':
- # Implement Elasticsearch version
- raise NotImplementedError("Elasticsearch version of add_media_with_keywords not yet implemented")
-
def insert_prompt_to_db(*args, **kwargs):
if db_type == 'sqlite':
return sqlite_insert_prompt_to_db(*args, **kwargs)
@@ -540,7 +533,6 @@ def mark_as_trash(media_id: int) -> None:
else:
raise ValueError(f"Unsupported database type: {db_type}")
-
def get_latest_transcription(*args, **kwargs):
if db_type == 'sqlite':
return sqlite_get_latest_transcription(*args, **kwargs)
diff --git a/App_Function_Libraries/DB/Prompts_DB.py b/App_Function_Libraries/DB/Prompts_DB.py
index bb1a900f8..68d8eae55 100644
--- a/App_Function_Libraries/DB/Prompts_DB.py
+++ b/App_Function_Libraries/DB/Prompts_DB.py
@@ -131,20 +131,6 @@ def list_prompts(page=1, per_page=10):
total_pages = (total_count + per_page - 1) // per_page
return prompts, total_pages, page
-# This will not scale. For a large number of prompts, use a more efficient method.
-# FIXME - see above statement.
-def load_preset_prompts():
- logging.debug("load_preset_prompts: Loading preset prompts.")
- try:
- with sqlite3.connect(get_database_path('prompts.db')) as conn:
- cursor = conn.cursor()
- cursor.execute('SELECT name FROM Prompts ORDER BY name ASC')
- prompts = [row[0] for row in cursor.fetchall()]
- return prompts
- except sqlite3.Error as e:
- print(f"Database error: {e}")
- return []
-
def insert_prompt_to_db(title, author, description, system_prompt, user_prompt, keywords=None):
return add_prompt(title, author, description, system_prompt, user_prompt, keywords)
diff --git a/App_Function_Libraries/Gradio_Related.py b/App_Function_Libraries/Gradio_Related.py
index 9c29bacc1..4f4e217d0 100644
--- a/App_Function_Libraries/Gradio_Related.py
+++ b/App_Function_Libraries/Gradio_Related.py
@@ -496,12 +496,13 @@ def launch_ui(share_public=None, server_mode=False):
create_ragdb_keyword_items_tab()
with gr.TabItem("Prompts", id='view prompts group', visible=True):
- create_prompt_view_tab()
- create_prompt_search_tab()
- create_prompt_edit_tab()
- create_prompt_clone_tab()
- create_prompt_suggestion_tab()
- create_prompts_export_tab()
+ with gr.Tabs():
+ create_prompt_view_tab()
+ create_prompt_search_tab()
+ create_prompt_edit_tab()
+ create_prompt_clone_tab()
+ create_prompt_suggestion_tab()
+ create_prompts_export_tab()
with gr.TabItem("Manage Media DB Items", id="manage group", visible=True):
create_media_edit_tab()
diff --git a/App_Function_Libraries/Gradio_UI/Anki_tab.py b/App_Function_Libraries/Gradio_UI/Anki_tab.py
index 9b3fa42c8..4f261f9b5 100644
--- a/App_Function_Libraries/Gradio_UI/Anki_tab.py
+++ b/App_Function_Libraries/Gradio_UI/Anki_tab.py
@@ -4,27 +4,25 @@
# Imports
import json
import logging
-from typing import Optional, Tuple, List
+import os
+import tempfile
+from typing import Optional, Tuple, List, Dict
#
# External Imports
+import genanki
import gradio as gr
-
+#
+# Local Imports
from App_Function_Libraries.Chat.Chat_Functions import approximate_token_count, update_chat_content, save_chat_history, \
save_chat_history_to_db_wrapper
-from App_Function_Libraries.DB.DB_Manager import load_preset_prompts
+from App_Function_Libraries.DB.DB_Manager import list_prompts
from App_Function_Libraries.Gradio_UI.Chat_ui import update_dropdown_multiple, chat_wrapper, update_selected_parts, \
search_conversations, regenerate_last_message, load_conversation, debug_output
-from App_Function_Libraries.Gradio_UI.Gradio_Shared import update_user_prompt
-#from outlines import models, prompts
-#
-# Local Imports
from App_Function_Libraries.Third_Party.Anki import sanitize_html, generate_card_choices, \
export_cards, load_card_for_editing, handle_file_upload, \
validate_for_ui, update_card_with_validation, update_card_choices, enhanced_file_upload, \
handle_validation
from App_Function_Libraries.Utils.Utils import default_api_endpoint, global_api_endpoints, format_api_name
-
-
#
############################################################################################################
#
@@ -374,12 +372,6 @@ def process_validation_result(is_valid, message):
def create_anki_generator_tab():
- import genanki
- import json
- from typing import List, Dict, Any
- import tempfile
- import os
-
with gr.TabItem("Anki Deck Generator", visible=True):
try:
default_value = None
@@ -402,6 +394,7 @@ def create_anki_generator_tab():
media_content = gr.State({})
selected_parts = gr.State([])
conversation_id = gr.State(None)
+ initial_prompts, total_pages, current_page = list_prompts(page=1, per_page=10)
with gr.Row():
with gr.Column(scale=1):
@@ -447,12 +440,19 @@ def create_anki_generator_tab():
custom_prompt_checkbox = gr.Checkbox(label="Use a Custom Prompt",
value=False,
visible=True)
- preset_prompt_checkbox = gr.Checkbox(label="Use a pre-set Prompt",
+ preset_prompt_checkbox = gr.Checkbox(label="Use a Pre-set Prompt",
value=False,
visible=True)
- preset_prompt = gr.Dropdown(label="Select Preset Prompt",
- choices=load_preset_prompts(),
- visible=False)
+ with gr.Row(visible=False) as preset_prompt_controls:
+ prev_prompt_page = gr.Button("Previous")
+ next_prompt_page = gr.Button("Next")
+ current_prompt_page_text = gr.Text(f"Page {current_page} of {total_pages}")
+ current_prompt_page_state = gr.State(value=1)
+
+ preset_prompt = gr.Dropdown(
+ label="Select Preset Prompt",
+ choices=initial_prompts
+ )
user_prompt = gr.Textbox(label="Custom Prompt",
placeholder="Enter custom prompt here",
lines=3,
@@ -475,44 +475,63 @@ def create_anki_generator_tab():
save_chat_history_as_file = gr.Button("Save Chat History as File")
download_file = gr.File(label="Download Chat History")
- # Restore original functionality
search_button.click(
fn=update_dropdown_multiple,
inputs=[search_query_input, search_type_input, keyword_filter_input],
outputs=[items_output, item_mapping]
)
- def update_prompts(preset_name):
- prompts = update_user_prompt(preset_name)
+ def update_prompt_visibility(custom_prompt_checked, preset_prompt_checked):
+ user_prompt_visible = custom_prompt_checked
+ system_prompt_visible = custom_prompt_checked
+ preset_prompt_visible = preset_prompt_checked
+ preset_prompt_controls_visible = preset_prompt_checked
return (
- gr.update(value=prompts["user_prompt"], visible=True),
- gr.update(value=prompts["system_prompt"], visible=True)
+ gr.update(visible=user_prompt_visible, interactive=user_prompt_visible),
+ gr.update(visible=system_prompt_visible, interactive=system_prompt_visible),
+ gr.update(visible=preset_prompt_visible, interactive=preset_prompt_visible),
+ gr.update(visible=preset_prompt_controls_visible)
+ )
+
+ def update_prompt_page(direction, current_page_val):
+ new_page = current_page_val + direction
+ if new_page < 1:
+ new_page = 1
+ prompts, total_pages, _ = list_prompts(page=new_page, per_page=20)
+ if new_page > total_pages:
+ new_page = total_pages
+ prompts, total_pages, _ = list_prompts(page=new_page, per_page=20)
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=f"Page {new_page} of {total_pages}"),
+ new_page
)
def clear_chat():
return [], None # Return empty list for chatbot and None for conversation_id
- clear_chat_button.click(
- clear_chat,
- outputs=[chatbot, conversation_id]
+ custom_prompt_checkbox.change(
+ update_prompt_visibility,
+ inputs=[custom_prompt_checkbox, preset_prompt_checkbox],
+ outputs=[user_prompt, system_prompt_input, preset_prompt, preset_prompt_controls]
)
- preset_prompt.change(
- update_prompts,
- inputs=preset_prompt,
- outputs=[user_prompt, system_prompt_input]
+ preset_prompt_checkbox.change(
+ update_prompt_visibility,
+ inputs=[custom_prompt_checkbox, preset_prompt_checkbox],
+ outputs=[user_prompt, system_prompt_input, preset_prompt, preset_prompt_controls]
)
- custom_prompt_checkbox.change(
- fn=lambda x: (gr.update(visible=x), gr.update(visible=x)),
- inputs=[custom_prompt_checkbox],
- outputs=[user_prompt, system_prompt_input]
+ prev_prompt_page.click(
+ lambda x: update_prompt_page(-1, x),
+ inputs=[current_prompt_page_state],
+ outputs=[preset_prompt, current_prompt_page_text, current_prompt_page_state]
)
- preset_prompt_checkbox.change(
- fn=lambda x: gr.update(visible=x),
- inputs=[preset_prompt_checkbox],
- outputs=[preset_prompt]
+ next_prompt_page.click(
+ lambda x: update_prompt_page(1, x),
+ inputs=[current_prompt_page_state],
+ outputs=[preset_prompt, current_prompt_page_text, current_prompt_page_state]
)
submit.click(
@@ -534,6 +553,12 @@ def clear_chat():
outputs=[token_count_display]
)
+
+ clear_chat_button.click(
+ clear_chat,
+ outputs=[chatbot, conversation_id]
+ )
+
items_output.change(
update_chat_content,
inputs=[items_output, use_content, use_summary, use_prompt, item_mapping],
diff --git a/App_Function_Libraries/Gradio_UI/Audio_ingestion_tab.py b/App_Function_Libraries/Gradio_UI/Audio_ingestion_tab.py
index a9317ba17..67cf2a22b 100644
--- a/App_Function_Libraries/Gradio_UI/Audio_ingestion_tab.py
+++ b/App_Function_Libraries/Gradio_UI/Audio_ingestion_tab.py
@@ -9,7 +9,7 @@
#
# Local Imports
from App_Function_Libraries.Audio.Audio_Files import process_audio_files
-from App_Function_Libraries.DB.DB_Manager import load_preset_prompts
+from App_Function_Libraries.DB.DB_Manager import list_prompts
from App_Function_Libraries.Gradio_UI.Chat_ui import update_user_prompt
from App_Function_Libraries.Gradio_UI.Gradio_Shared import whisper_models
from App_Function_Libraries.Utils.Utils import cleanup_temp_files, default_api_endpoint, global_api_endpoints, \
@@ -60,54 +60,133 @@ def create_audio_processing_tab():
keep_timestamps_input = gr.Checkbox(label="Keep Timestamps", value=True)
with gr.Row():
- custom_prompt_checkbox = gr.Checkbox(label="Use a Custom Prompt",
- value=False,
- visible=True)
- preset_prompt_checkbox = gr.Checkbox(label="Use a pre-set Prompt",
- value=False,
- visible=True)
+ custom_prompt_checkbox = gr.Checkbox(
+ label="Use a Custom Prompt",
+ value=False,
+ visible=True
+ )
+ preset_prompt_checkbox = gr.Checkbox(
+ label="Use a pre-set Prompt",
+ value=False,
+ visible=True
+ )
+
+ # Initialize state variables for pagination
+ current_page_state = gr.State(value=1)
+ total_pages_state = gr.State(value=1)
+
with gr.Row():
- preset_prompt = gr.Dropdown(label="Select Preset Prompt",
- choices=load_preset_prompts(),
- visible=False)
+ # Add pagination controls
+ preset_prompt = gr.Dropdown(
+ label="Select Preset Prompt",
+ choices=[],
+ visible=False
+ )
with gr.Row():
- custom_prompt_input = gr.Textbox(label="Custom Prompt",
- placeholder="Enter custom prompt here",
- lines=3,
- visible=False)
+ prev_page_button = gr.Button("Previous Page", visible=False)
+ page_display = gr.Markdown("Page 1 of X", visible=False)
+ next_page_button = gr.Button("Next Page", visible=False)
+
with gr.Row():
- system_prompt_input = gr.Textbox(label="System Prompt",
- value="""You are a bulleted notes specialist. [INST]```When creating comprehensive bulleted notes, you should follow these guidelines: Use multiple headings based on the referenced topics, not categories like quotes or terms. Headings should be surrounded by bold formatting and not be listed as bullet points themselves. Leave no space between headings and their corresponding list items underneath. Important terms within the content should be emphasized by setting them in bold font. Any text that ends with a colon should also be bolded. Before submitting your response, review the instructions, and make any corrections necessary to adhered to the specified format. Do not reference these instructions within the notes.``` \nBased on the content between backticks create comprehensive bulleted notes.[/INST]
-**Bulleted Note Creation Guidelines**
-
-**Headings**:
-- Based on referenced topics, not categories like quotes or terms
-- Surrounded by **bold** formatting
-- Not listed as bullet points
-- No space between headings and list items underneath
-
-**Emphasis**:
-- **Important terms** set in bold font
-- **Text ending in a colon**: also bolded
-
-**Review**:
-- Ensure adherence to specified format
-- Do not reference these instructions in your response.[INST] {{ .Prompt }} [/INST]
-""",
- lines=3,
- visible=False)
+ custom_prompt_input = gr.Textbox(
+ label="Custom Prompt",
+ placeholder="Enter custom prompt here",
+ lines=3,
+ visible=False
+ )
+ with gr.Row():
+ system_prompt_input = gr.Textbox(
+ label="System Prompt",
+ value="""You are a bulleted notes specialist. [INST]```When creating comprehensive bulleted notes, you should follow these guidelines: Use multiple headings based on the referenced topics, not categories like quotes or terms. Headings should be surrounded by bold formatting and not be listed as bullet points themselves. Leave no space between headings and their corresponding list items underneath. Important terms within the content should be emphasized by setting them in bold font. Any text that ends with a colon should also be bolded. Before submitting your response, review the instructions, and make any corrections necessary to adhere to the specified format. Do not reference these instructions within the notes.``` \nBased on the content between backticks create comprehensive bulleted notes.[/INST]
+ **Bulleted Note Creation Guidelines**
+
+ **Headings**:
+ - Based on referenced topics, not categories like quotes or terms
+ - Surrounded by **bold** formatting
+ - Not listed as bullet points
+ - No space between headings and list items underneath
+
+ **Emphasis**:
+ - **Important terms** set in bold font
+ - **Text ending in a colon**: also bolded
+
+ **Review**:
+ - Ensure adherence to specified format
+ - Do not reference these instructions in your response.[INST] {{ .Prompt }} [/INST]
+ """,
+ lines=3,
+ visible=False
+ )
custom_prompt_checkbox.change(
fn=lambda x: (gr.update(visible=x), gr.update(visible=x)),
inputs=[custom_prompt_checkbox],
outputs=[custom_prompt_input, system_prompt_input]
)
+
+ # Handle preset prompt checkbox change
+ def on_preset_prompt_checkbox_change(is_checked):
+ if is_checked:
+ prompts, total_pages, current_page = list_prompts(page=1, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(visible=True, interactive=True, choices=prompts), # preset_prompt
+ gr.update(visible=True), # prev_page_button
+ gr.update(visible=True), # next_page_button
+ gr.update(value=page_display_text, visible=True), # page_display
+ current_page, # current_page_state
+ total_pages # total_pages_state
+ )
+ else:
+ return (
+ gr.update(visible=False, interactive=False), # preset_prompt
+ gr.update(visible=False), # prev_page_button
+ gr.update(visible=False), # next_page_button
+ gr.update(visible=False), # page_display
+ 1, # current_page_state
+ 1 # total_pages_state
+ )
+
preset_prompt_checkbox.change(
- fn=lambda x: gr.update(visible=x),
+ fn=on_preset_prompt_checkbox_change,
inputs=[preset_prompt_checkbox],
- outputs=[preset_prompt]
+ outputs=[preset_prompt, prev_page_button, next_page_button, page_display, current_page_state, total_pages_state]
+ )
+
+ # Pagination button functions
+ def on_prev_page_click(current_page, total_pages):
+ new_page = max(current_page - 1, 1)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
)
+ # Update prompts when a preset is selected
def update_prompts(preset_name):
prompts = update_user_prompt(preset_name)
return (
@@ -117,7 +196,7 @@ def update_prompts(preset_name):
preset_prompt.change(
update_prompts,
- inputs=preset_prompt,
+ inputs=[preset_prompt],
outputs=[custom_prompt_input, system_prompt_input]
)
# Refactored API selection dropdown
diff --git a/App_Function_Libraries/Gradio_UI/Chat_ui.py b/App_Function_Libraries/Gradio_UI/Chat_ui.py
index 8f95f05d2..6df00168d 100644
--- a/App_Function_Libraries/Gradio_UI/Chat_ui.py
+++ b/App_Function_Libraries/Gradio_UI/Chat_ui.py
@@ -14,9 +14,9 @@
# Local Imports
from App_Function_Libraries.Chat.Chat_Functions import approximate_token_count, chat, save_chat_history, \
update_chat_content, save_chat_history_to_db_wrapper
-from App_Function_Libraries.DB.DB_Manager import load_preset_prompts, db, load_chat_history, start_new_conversation,\
+from App_Function_Libraries.DB.DB_Manager import db, load_chat_history, start_new_conversation, \
save_message, search_conversations_by_keywords, \
- get_all_conversations, delete_messages_in_conversation, search_media_db
+ get_all_conversations, delete_messages_in_conversation, search_media_db, list_prompts
from App_Function_Libraries.DB.RAG_QA_Chat_DB import get_db_connection
from App_Function_Libraries.Gradio_UI.Gradio_Shared import update_dropdown, update_user_prompt
from App_Function_Libraries.Metrics.metrics_logger import log_counter, log_histogram
@@ -310,23 +310,35 @@ def create_chat_interface():
label="API for Chat Interaction (Optional)"
)
api_key = gr.Textbox(label="API Key (if required)", type="password")
+
+ # Initialize state variables for pagination
+ current_page_state = gr.State(value=1)
+ total_pages_state = gr.State(value=1)
+
custom_prompt_checkbox = gr.Checkbox(label="Use a Custom Prompt",
value=False,
visible=True)
preset_prompt_checkbox = gr.Checkbox(label="Use a pre-set Prompt",
value=False,
visible=True)
- preset_prompt = gr.Dropdown(label="Select Preset Prompt",
- choices=load_preset_prompts(),
- visible=False)
- user_prompt = gr.Textbox(label="Custom Prompt",
- placeholder="Enter custom prompt here",
- lines=3,
- visible=False)
- system_prompt_input = gr.Textbox(label="System Prompt",
- value="You are a helpful AI assitant",
- lines=3,
- visible=False)
+ with gr.Row():
+ # Add pagination controls
+ preset_prompt = gr.Dropdown(label="Select Preset Prompt",
+ choices=[],
+ visible=False)
+ with gr.Row():
+ prev_page_button = gr.Button("Previous Page", visible=False)
+ page_display = gr.Markdown("Page 1 of X", visible=False)
+ next_page_button = gr.Button("Next Page", visible=False)
+ system_prompt_input = gr.Textbox(label="System Prompt",
+ value="You are a helpful AI assistant",
+ lines=3,
+ visible=False)
+ with gr.Row():
+ user_prompt = gr.Textbox(label="Custom Prompt",
+ placeholder="Enter custom prompt here",
+ lines=3,
+ visible=False)
with gr.Column(scale=2):
chatbot = gr.Chatbot(height=800, elem_classes="chatbot-container")
msg = gr.Textbox(label="Enter your message")
@@ -376,9 +388,62 @@ def clear_chat():
outputs=[chatbot, conversation_id]
)
+ # Function to handle preset prompt checkbox change
+ def on_preset_prompt_checkbox_change(is_checked):
+ if is_checked:
+ prompts, total_pages, current_page = list_prompts(page=1, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(visible=True, interactive=True, choices=prompts), # preset_prompt
+ gr.update(visible=True), # prev_page_button
+ gr.update(visible=True), # next_page_button
+ gr.update(value=page_display_text, visible=True), # page_display
+ current_page, # current_page_state
+ total_pages # total_pages_state
+ )
+ else:
+ return (
+ gr.update(visible=False, interactive=False), # preset_prompt
+ gr.update(visible=False), # prev_page_button
+ gr.update(visible=False), # next_page_button
+ gr.update(visible=False), # page_display
+ 1, # current_page_state
+ 1 # total_pages_state
+ )
+
+ preset_prompt_checkbox.change(
+ fn=on_preset_prompt_checkbox_change,
+ inputs=[preset_prompt_checkbox],
+ outputs=[preset_prompt, prev_page_button, next_page_button, page_display, current_page_state, total_pages_state]
+ )
+
+ def on_prev_page_click(current_page, total_pages):
+ new_page = max(current_page - 1, 1)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return gr.update(choices=prompts), gr.update(value=page_display_text), current_page
+
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return gr.update(choices=prompts), gr.update(value=page_display_text), current_page
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
preset_prompt.change(
update_prompts,
- inputs=preset_prompt,
+ inputs=[preset_prompt],
outputs=[user_prompt, system_prompt_input]
)
@@ -388,12 +453,6 @@ def clear_chat():
outputs=[user_prompt, system_prompt_input]
)
- preset_prompt_checkbox.change(
- fn=lambda x: gr.update(visible=x),
- inputs=[preset_prompt_checkbox],
- outputs=[preset_prompt]
- )
-
submit.click(
chat_wrapper,
inputs=[msg, chatbot, media_content, selected_parts, api_endpoint, api_key, user_prompt, conversation_id,
@@ -407,9 +466,9 @@ def clear_chat():
lambda: (gr.update(value=""), gr.update(value="")),
outputs=[user_prompt, system_prompt_input]
).then(
- lambda history: approximate_token_count(history),
- inputs=[chatbot],
- outputs=[token_count_display]
+ lambda history: approximate_token_count(history),
+ inputs=[chatbot],
+ outputs=[token_count_display]
)
items_output.change(
@@ -534,17 +593,45 @@ def create_chat_interface_stacked():
label="API for Chat Interaction (Optional)"
)
api_key = gr.Textbox(label="API Key (if required)", type="password")
- preset_prompt = gr.Dropdown(label="Select Preset Prompt",
- choices=load_preset_prompts(),
- visible=True)
- system_prompt = gr.Textbox(label="System Prompt",
- value="You are a helpful AI assistant.",
- lines=4,
- visible=True)
- user_prompt = gr.Textbox(label="Custom User Prompt",
- placeholder="Enter custom prompt here",
- lines=4,
- visible=True)
+
+ # Initialize state variables for pagination
+ current_page_state = gr.State(value=1)
+ total_pages_state = gr.State(value=1)
+
+ custom_prompt_checkbox = gr.Checkbox(
+ label="Use a Custom Prompt",
+ value=False,
+ visible=True
+ )
+ preset_prompt_checkbox = gr.Checkbox(
+ label="Use a pre-set Prompt",
+ value=False,
+ visible=True
+ )
+
+ with gr.Row():
+ preset_prompt = gr.Dropdown(
+ label="Select Preset Prompt",
+ choices=[],
+ visible=False
+ )
+ with gr.Row():
+ prev_page_button = gr.Button("Previous Page", visible=False)
+ page_display = gr.Markdown("Page 1 of X", visible=False)
+ next_page_button = gr.Button("Next Page", visible=False)
+
+ system_prompt = gr.Textbox(
+ label="System Prompt",
+ value="You are a helpful AI assistant.",
+ lines=4,
+ visible=False
+ )
+ user_prompt = gr.Textbox(
+ label="Custom User Prompt",
+ placeholder="Enter custom prompt here",
+ lines=4,
+ visible=False
+ )
gr.Markdown("Scroll down for the chat window...")
with gr.Row():
with gr.Column(scale=1):
@@ -673,9 +760,77 @@ def clear_chat():
outputs=[chatbot, conversation_id, token_count_display]
)
+ # Handle custom prompt checkbox change
+ def on_custom_prompt_checkbox_change(is_checked):
+ return (
+ gr.update(visible=is_checked),
+ gr.update(visible=is_checked)
+ )
+
+ custom_prompt_checkbox.change(
+ fn=on_custom_prompt_checkbox_change,
+ inputs=[custom_prompt_checkbox],
+ outputs=[user_prompt, system_prompt]
+ )
+
+ # Handle preset prompt checkbox change
+ def on_preset_prompt_checkbox_change(is_checked):
+ if is_checked:
+ prompts, total_pages, current_page = list_prompts(page=1, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(visible=True, interactive=True, choices=prompts), # preset_prompt
+ gr.update(visible=True), # prev_page_button
+ gr.update(visible=True), # next_page_button
+ gr.update(value=page_display_text, visible=True), # page_display
+ current_page, # current_page_state
+ total_pages # total_pages_state
+ )
+ else:
+ return (
+ gr.update(visible=False, interactive=False), # preset_prompt
+ gr.update(visible=False), # prev_page_button
+ gr.update(visible=False), # next_page_button
+ gr.update(visible=False), # page_display
+ 1, # current_page_state
+ 1 # total_pages_state
+ )
+
+ preset_prompt_checkbox.change(
+ fn=on_preset_prompt_checkbox_change,
+ inputs=[preset_prompt_checkbox],
+ outputs=[preset_prompt, prev_page_button, next_page_button, page_display, current_page_state, total_pages_state]
+ )
+
+ # Pagination button functions
+ def on_prev_page_click(current_page, total_pages):
+ new_page = max(current_page - 1, 1)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return gr.update(choices=prompts), gr.update(value=page_display_text), current_page
+
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return gr.update(choices=prompts), gr.update(value=page_display_text), current_page
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ # Update prompts when a preset is selected
preset_prompt.change(
update_prompts,
- inputs=preset_prompt,
+ inputs=[preset_prompt],
outputs=[user_prompt, system_prompt]
)
@@ -787,8 +942,29 @@ def create_chat_interface_multi_api():
use_summary = gr.Checkbox(label="Use Summary")
use_prompt = gr.Checkbox(label="Use Prompt")
with gr.Column():
- preset_prompt = gr.Dropdown(label="Select Preset Prompt", choices=load_preset_prompts(), visible=True)
- system_prompt = gr.Textbox(label="System Prompt", value="You are a helpful AI assistant.", lines=5)
+ # Initialize state variables for pagination
+ current_page_state = gr.State(value=1)
+ total_pages_state = gr.State(value=1)
+
+ custom_prompt_checkbox = gr.Checkbox(label="Use a Custom Prompt",
+ value=False,
+ visible=True)
+ preset_prompt_checkbox = gr.Checkbox(label="Use a pre-set Prompt",
+ value=False,
+ visible=True)
+ with gr.Row():
+ # Add pagination controls
+ preset_prompt = gr.Dropdown(label="Select Preset Prompt",
+ choices=[],
+ visible=False)
+ with gr.Row():
+ prev_page_button = gr.Button("Previous Page", visible=False)
+ page_display = gr.Markdown("Page 1 of X", visible=False)
+ next_page_button = gr.Button("Next Page", visible=False)
+ system_prompt = gr.Textbox(label="System Prompt",
+ value="You are a helpful AI assistant.",
+ lines=5,
+ visible=True)
user_prompt = gr.Textbox(label="Modify Prompt (Prefixed to your message every time)", lines=5,
value="", visible=True)
@@ -840,8 +1016,95 @@ def create_chat_interface_multi_api():
outputs=[items_output, item_mapping]
)
+ def update_prompts(preset_name):
+ prompts = update_user_prompt(preset_name)
+ return (
+ gr.update(value=prompts["user_prompt"], visible=True),
+ gr.update(value=prompts["system_prompt"], visible=True)
+ )
+
+ def on_custom_prompt_checkbox_change(is_checked):
+ return (
+ gr.update(visible=is_checked),
+ gr.update(visible=is_checked)
+ )
+
+ custom_prompt_checkbox.change(
+ fn=on_custom_prompt_checkbox_change,
+ inputs=[custom_prompt_checkbox],
+ outputs=[user_prompt, system_prompt]
+ )
+
+ def clear_all_chats():
+ return [[]] * 3 + [[]] * 3 + [0] * 3
+
+ clear_chat_button.click(
+ clear_all_chats,
+ outputs=chatbots + chat_history + token_count_displays
+ )
+
+ def on_preset_prompt_checkbox_change(is_checked):
+ if is_checked:
+ prompts, total_pages, current_page = list_prompts(page=1, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(visible=True, interactive=True, choices=prompts), # preset_prompt
+ gr.update(visible=True), # prev_page_button
+ gr.update(visible=True), # next_page_button
+ gr.update(value=page_display_text, visible=True), # page_display
+ current_page, # current_page_state
+ total_pages # total_pages_state
+ )
+ else:
+ return (
+ gr.update(visible=False, interactive=False), # preset_prompt
+ gr.update(visible=False), # prev_page_button
+ gr.update(visible=False), # next_page_button
+ gr.update(visible=False), # page_display
+ 1, # current_page_state
+ 1 # total_pages_state
+ )
+
preset_prompt.change(update_user_prompt, inputs=preset_prompt, outputs=user_prompt)
+ preset_prompt_checkbox.change(
+ fn=on_preset_prompt_checkbox_change,
+ inputs=[preset_prompt_checkbox],
+ outputs=[preset_prompt, prev_page_button, next_page_button, page_display, current_page_state,
+ total_pages_state]
+ )
+
+ def on_prev_page_click(current_page, total_pages):
+ new_page = max(current_page - 1, 1)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return gr.update(choices=prompts), gr.update(value=page_display_text), current_page
+
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return gr.update(choices=prompts), gr.update(value=page_display_text), current_page
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ # Update prompts when a preset is selected
+ preset_prompt.change(
+ update_prompts,
+ inputs=[preset_prompt],
+ outputs=[user_prompt, system_prompt]
+ )
+
def clear_all_chats():
return [[]] * 3 + [[]] * 3 + [0] * 3
@@ -983,17 +1246,32 @@ def create_chat_interface_four():
with gr.TabItem("Four Independent API Chats", visible=True):
gr.Markdown("# Four Independent API Chat Interfaces")
+ # Initialize prompts during component creation
+ prompts, total_pages, current_page = list_prompts(page=1, per_page=10)
+ current_page_state = gr.State(value=current_page)
+ total_pages_state = gr.State(value=total_pages)
+ page_display_text = f"Page {current_page} of {total_pages}"
+
with gr.Row():
with gr.Column():
preset_prompt = gr.Dropdown(
- label="Select Preset Prompt",
- choices=load_preset_prompts(),
+ label="Select Preset Prompt (This will be prefixed to your messages, recommend copy/pasting and then clearing the User Prompt box)",
+ choices=prompts,
visible=True
)
+ prev_page_button = gr.Button("Previous Page", visible=True)
+ page_display = gr.Markdown(page_display_text, visible=True)
+ next_page_button = gr.Button("Next Page", visible=True)
user_prompt = gr.Textbox(
- label="Modify Prompt",
+ label="Modify User Prompt",
+ lines=3
+ )
+ system_prompt = gr.Textbox(
+ label="System Prompt",
+ value="You are a helpful AI assistant.",
lines=3
)
+
with gr.Column():
gr.Markdown("Scroll down for the chat windows...")
@@ -1027,7 +1305,6 @@ def create_single_chat_interface(index, user_prompt_component):
interactive=False)
clear_chat_button = gr.Button(f"Clear Chat {index + 1}")
-
# State to maintain chat history
chat_history = gr.State([])
@@ -1053,10 +1330,47 @@ def create_single_chat_interface(index, user_prompt_component):
create_single_chat_interface(i * 2 + j, user_prompt)
# Update user_prompt based on preset_prompt selection
+ def update_prompts(preset_name):
+ prompts = update_user_prompt(preset_name)
+ return gr.update(value=prompts["user_prompt"]), gr.update(value=prompts["system_prompt"])
+
preset_prompt.change(
- fn=update_user_prompt,
- inputs=preset_prompt,
- outputs=user_prompt
+ fn=update_prompts,
+ inputs=[preset_prompt],
+ outputs=[user_prompt, system_prompt]
+ )
+
+ # Pagination button functions
+ def on_prev_page_click(current_page, total_pages):
+ new_page = max(current_page - 1, 1)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
)
def chat_wrapper_single(message, chat_history, api_endpoint, api_key, temperature, user_prompt):
@@ -1165,11 +1479,10 @@ def regenerate_last_message(chat_history, api_endpoint, api_key, temperature, us
def clear_chat_single():
return [], [], 0
- for interface in chat_interfaces:
- interface['clear_chat_button'].click(
- clear_chat_single,
- outputs=[interface['chatbot'], interface['chat_history'], interface['token_count_display']]
- )
+ interface['clear_chat_button'].click(
+ clear_chat_single,
+ outputs=[interface['chatbot'], interface['chat_history'], interface['token_count_display']]
+ )
def chat_wrapper_single(message, chat_history, chatbot, api_endpoint, api_key, temperature, media_content,
diff --git a/App_Function_Libraries/Gradio_UI/Explain_summarize_tab.py b/App_Function_Libraries/Gradio_UI/Explain_summarize_tab.py
index fbf5505ac..50942fa91 100644
--- a/App_Function_Libraries/Gradio_UI/Explain_summarize_tab.py
+++ b/App_Function_Libraries/Gradio_UI/Explain_summarize_tab.py
@@ -7,7 +7,7 @@
# External Imports
import gradio as gr
-from App_Function_Libraries.DB.DB_Manager import load_preset_prompts
+from App_Function_Libraries.DB.DB_Manager import list_prompts
from App_Function_Libraries.Gradio_UI.Gradio_Shared import update_user_prompt
#
# Local Imports
@@ -37,32 +37,52 @@ def create_summarize_explain_tab():
except Exception as e:
logging.error(f"Error setting default API endpoint: {str(e)}")
default_value = None
+
with gr.TabItem("Analyze Text", visible=True):
gr.Markdown("# Analyze / Explain / Summarize Text without ingesting it into the DB")
+
+ # Initialize state variables for pagination
+ current_page_state = gr.State(value=1)
+ total_pages_state = gr.State(value=1)
+
with gr.Row():
with gr.Column():
with gr.Row():
- text_to_work_input = gr.Textbox(label="Text to be Explained or Summarized",
- placeholder="Enter the text you want explained or summarized here",
- lines=20)
+ text_to_work_input = gr.Textbox(
+ label="Text to be Explained or Summarized",
+ placeholder="Enter the text you want explained or summarized here",
+ lines=20
+ )
with gr.Row():
explanation_checkbox = gr.Checkbox(label="Explain Text", value=True)
summarization_checkbox = gr.Checkbox(label="Summarize Text", value=True)
- custom_prompt_checkbox = gr.Checkbox(label="Use a Custom Prompt",
- value=False,
- visible=True)
- preset_prompt_checkbox = gr.Checkbox(label="Use a pre-set Prompt",
- value=False,
- visible=True)
+ custom_prompt_checkbox = gr.Checkbox(
+ label="Use a Custom Prompt",
+ value=False,
+ visible=True
+ )
+ preset_prompt_checkbox = gr.Checkbox(
+ label="Use a pre-set Prompt",
+ value=False,
+ visible=True
+ )
with gr.Row():
- preset_prompt = gr.Dropdown(label="Select Preset Prompt",
- choices=load_preset_prompts(),
- visible=False)
+ # Add pagination controls
+ preset_prompt = gr.Dropdown(
+ label="Select Preset Prompt",
+ choices=[],
+ visible=False
+ )
+ prev_page_button = gr.Button("Previous Page", visible=False)
+ page_display = gr.Markdown("Page 1 of X", visible=False)
+ next_page_button = gr.Button("Next Page", visible=False)
with gr.Row():
- custom_prompt_input = gr.Textbox(label="Custom Prompt",
- placeholder="Enter custom prompt here",
- lines=3,
- visible=False)
+ custom_prompt_input = gr.Textbox(
+ label="Custom Prompt",
+ placeholder="Enter custom prompt here",
+ lines=10,
+ visible=False
+ )
with gr.Row():
system_prompt_input = gr.Textbox(label="System Prompt",
value="""You are a bulleted notes specialist. [INST]```When creating comprehensive bulleted notes, you should follow these guidelines: Use multiple headings based on the referenced topics, not categories like quotes or terms. Headings should be surrounded by bold formatting and not be listed as bullet points themselves. Leave no space between headings and their corresponding list items underneath. Important terms within the content should be emphasized by setting them in bold font. Any text that ends with a colon should also be bolded. Before submitting your response, review the instructions, and make any corrections necessary to adhered to the specified format. Do not reference these instructions within the notes.``` \nBased on the content between backticks create comprehensive bulleted notes.[/INST]
@@ -82,7 +102,7 @@ def create_summarize_explain_tab():
- Ensure adherence to specified format
- Do not reference these instructions in your response.[INST] {{ .Prompt }} [/INST]
""",
- lines=3,
+ lines=10,
visible=False,
interactive=True)
# Refactored API selection dropdown
@@ -92,8 +112,11 @@ def create_summarize_explain_tab():
label="API for Summarization/Analysis (Optional)"
)
with gr.Row():
- api_key_input = gr.Textbox(label="API Key (if required)", placeholder="Enter your API key here",
- type="password")
+ api_key_input = gr.Textbox(
+ label="API Key (if required)",
+ placeholder="Enter your API key here",
+ type="password"
+ )
with gr.Row():
explain_summarize_button = gr.Button("Explain/Summarize")
@@ -102,17 +125,83 @@ def create_summarize_explain_tab():
explanation_output = gr.Textbox(label="Explanation:", lines=20)
custom_prompt_output = gr.Textbox(label="Custom Prompt:", lines=20, visible=True)
+ # Handle custom prompt checkbox change
custom_prompt_checkbox.change(
fn=lambda x: (gr.update(visible=x), gr.update(visible=x)),
inputs=[custom_prompt_checkbox],
outputs=[custom_prompt_input, system_prompt_input]
)
+
+ # Handle preset prompt checkbox change
+ def on_preset_prompt_checkbox_change(is_checked):
+ if is_checked:
+ prompts, total_pages, current_page = list_prompts(page=1, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(visible=True, interactive=True, choices=prompts), # preset_prompt
+ gr.update(visible=True), # prev_page_button
+ gr.update(visible=True), # next_page_button
+ gr.update(value=page_display_text, visible=True), # page_display
+ current_page, # current_page_state
+ total_pages # total_pages_state
+ )
+ else:
+ return (
+ gr.update(visible=False, interactive=False), # preset_prompt
+ gr.update(visible=False), # prev_page_button
+ gr.update(visible=False), # next_page_button
+ gr.update(visible=False), # page_display
+ 1, # current_page_state
+ 1 # total_pages_state
+ )
+
preset_prompt_checkbox.change(
- fn=lambda x: gr.update(visible=x),
+ fn=on_preset_prompt_checkbox_change,
inputs=[preset_prompt_checkbox],
- outputs=[preset_prompt]
+ outputs=[
+ preset_prompt,
+ prev_page_button,
+ next_page_button,
+ page_display,
+ current_page_state,
+ total_pages_state
+ ]
)
+ # Pagination button functions
+ def on_prev_page_click(current_page, total_pages):
+ new_page = max(current_page - 1, 1)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ # Update prompts when a preset is selected
def update_prompts(preset_name):
prompts = update_user_prompt(preset_name)
return (
@@ -121,18 +210,27 @@ def update_prompts(preset_name):
)
preset_prompt.change(
- update_prompts,
- inputs=preset_prompt,
+ fn=update_prompts,
+ inputs=[preset_prompt],
outputs=[custom_prompt_input, system_prompt_input]
)
explain_summarize_button.click(
fn=summarize_explain_text,
- inputs=[text_to_work_input, api_endpoint, api_key_input, summarization_checkbox, explanation_checkbox, custom_prompt_input, system_prompt_input],
+ inputs=[
+ text_to_work_input,
+ api_endpoint,
+ api_key_input,
+ summarization_checkbox,
+ explanation_checkbox,
+ custom_prompt_input,
+ system_prompt_input
+ ],
outputs=[summarization_output, explanation_output, custom_prompt_output]
)
+
def summarize_explain_text(message, api_endpoint, api_key, summarization, explanation, custom_prompt, custom_system_prompt,):
global custom_prompt_output
summarization_response = None
diff --git a/App_Function_Libraries/Gradio_UI/Gradio_Shared.py b/App_Function_Libraries/Gradio_UI/Gradio_Shared.py
index cfb2ea9c4..fd39a02cd 100644
--- a/App_Function_Libraries/Gradio_UI/Gradio_Shared.py
+++ b/App_Function_Libraries/Gradio_UI/Gradio_Shared.py
@@ -216,11 +216,6 @@ def format_content(content):
return formatted_content
-def update_prompt_dropdown():
- prompt_names = list_prompts()
- return gr.update(choices=prompt_names)
-
-
def display_prompt_details(selected_prompt):
if selected_prompt:
prompts = update_user_prompt(selected_prompt)
diff --git a/App_Function_Libraries/Gradio_UI/Import_Functionality.py b/App_Function_Libraries/Gradio_UI/Import_Functionality.py
index c69d5e359..37934d539 100644
--- a/App_Function_Libraries/Gradio_UI/Import_Functionality.py
+++ b/App_Function_Libraries/Gradio_UI/Import_Functionality.py
@@ -22,8 +22,8 @@
#
# Local Imports
-from App_Function_Libraries.DB.DB_Manager import insert_prompt_to_db, load_preset_prompts, import_obsidian_note_to_db, \
- add_media_to_database
+from App_Function_Libraries.DB.DB_Manager import insert_prompt_to_db, import_obsidian_note_to_db, \
+ add_media_to_database, list_prompts
from App_Function_Libraries.Prompt_Handling import import_prompt_from_file, import_prompts_from_zip#
from App_Function_Libraries.Summarization.Summarization_General_Lib import perform_summarization
#
@@ -210,15 +210,6 @@ def save_prompt_to_db(title, author, system, user, keywords):
outputs=save_output
)
- def update_prompt_dropdown():
- return gr.update(choices=load_preset_prompts())
-
- save_button.click(
- fn=update_prompt_dropdown,
- inputs=[],
- outputs=[gr.Dropdown(label="Select Preset Prompt")]
- )
-
def create_import_item_tab():
with gr.TabItem("Import Markdown/Text Files", visible=True):
gr.Markdown("# Import a markdown file or text file into the database")
@@ -257,11 +248,18 @@ def create_import_multiple_prompts_tab():
gr.Markdown("# Import multiple prompts into the database")
gr.Markdown("Upload a zip file containing multiple prompt files (txt or md)")
+ # Initialize state variables for pagination
+ current_page_state = gr.State(value=1)
+ total_pages_state = gr.State(value=1)
+
with gr.Row():
with gr.Column():
zip_file = gr.File(label="Upload zip file for import", file_types=["zip"])
import_button = gr.Button("Import Prompts")
prompts_dropdown = gr.Dropdown(label="Select Prompt to Edit", choices=[])
+ prev_page_button = gr.Button("Previous Page", visible=False)
+ page_display = gr.Markdown("Page 1 of X", visible=False)
+ next_page_button = gr.Button("Next Page", visible=False)
title_input = gr.Textbox(label="Title", placeholder="Enter the title of the content")
author_input = gr.Textbox(label="Author", placeholder="Enter the author's name")
system_input = gr.Textbox(label="System", placeholder="Enter the system message for the prompt",
@@ -275,6 +273,10 @@ def create_import_multiple_prompts_tab():
save_output = gr.Textbox(label="Save Status")
prompts_display = gr.Textbox(label="Identified Prompts")
+ # State to store imported prompts
+ zip_import_state = gr.State([])
+
+ # Function to handle zip import
def handle_zip_import(zip_file):
result = import_prompts_from_zip(zip_file)
if isinstance(result, list):
@@ -285,6 +287,13 @@ def handle_zip_import(zip_file):
else:
return gr.update(value=result), [], gr.update(value=""), []
+ import_button.click(
+ fn=handle_zip_import,
+ inputs=[zip_file],
+ outputs=[import_output, prompts_dropdown, prompts_display, zip_import_state]
+ )
+
+ # Function to handle prompt selection from imported prompts
def handle_prompt_selection(selected_title, prompts):
selected_prompt = next((prompt for prompt in prompts if prompt['title'] == selected_title), None)
if selected_prompt:
@@ -312,23 +321,68 @@ def handle_prompt_selection(selected_title, prompts):
outputs=[title_input, author_input, system_input, user_input, keywords_input]
)
+ # Function to save prompt to the database
def save_prompt_to_db(title, author, system, user, keywords):
keyword_list = [k.strip() for k in keywords.split(',') if k.strip()]
- return insert_prompt_to_db(title, author, system, user, keyword_list)
+ result = insert_prompt_to_db(title, author, system, user, keyword_list)
+ return result
save_button.click(
fn=save_prompt_to_db,
inputs=[title_input, author_input, system_input, user_input, keywords_input],
- outputs=save_output
+ outputs=[save_output]
)
+ # Adding pagination controls to navigate prompts in the database
+ def on_prev_page_click(current_page, total_pages):
+ new_page = max(current_page - 1, 1)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[prompts_dropdown, page_display, current_page_state]
+ )
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[prompts_dropdown, page_display, current_page_state]
+ )
+
+ # Function to update prompts dropdown after saving to the database
def update_prompt_dropdown():
- return gr.update(choices=load_preset_prompts())
+ prompts, total_pages, current_page = list_prompts(page=1, per_page=10)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(visible=True),
+ gr.update(value=page_display_text, visible=True),
+ current_page,
+ total_pages
+ )
+ # Update the dropdown after saving
save_button.click(
fn=update_prompt_dropdown,
inputs=[],
- outputs=[gr.Dropdown(label="Select Preset Prompt")]
+ outputs=[prompts_dropdown, prev_page_button, page_display, current_page_state, total_pages_state]
)
@@ -532,8 +586,7 @@ def import_files(
# Handle zip files
if filename.lower().endswith('.zip'):
zip_files = self.extract_zip(file_path)
- progress.tqdm(desc=f"Processing files from {filename}")
- for zip_filename, content in zip_files:
+ for zip_filename, content in progress.tqdm(zip_files, desc=f"Processing files from {filename}"):
conv_id = self.import_single_file(
db=db,
content=content,
diff --git a/App_Function_Libraries/Gradio_UI/Media_edit.py b/App_Function_Libraries/Gradio_UI/Media_edit.py
index 7f1b01a93..4cbfdd2ef 100644
--- a/App_Function_Libraries/Gradio_UI/Media_edit.py
+++ b/App_Function_Libraries/Gradio_UI/Media_edit.py
@@ -10,8 +10,8 @@
#
# Local Imports
from App_Function_Libraries.DB.DB_Manager import add_prompt, update_media_content, db, add_or_update_prompt, \
- load_prompt_details, fetch_keywords_for_media, update_keywords_for_media
-from App_Function_Libraries.Gradio_UI.Gradio_Shared import update_dropdown, update_prompt_dropdown
+ load_prompt_details, fetch_keywords_for_media, update_keywords_for_media, fetch_prompt_details, list_prompts
+from App_Function_Libraries.Gradio_UI.Gradio_Shared import update_dropdown
from App_Function_Libraries.DB.SQLite_DB import fetch_item_details
@@ -199,6 +199,11 @@ def save_cloned_item(selected_item, item_mapping, content, prompt, summary, new_
def create_prompt_edit_tab():
+ # Initialize state variables for pagination
+ current_page_state = gr.State(value=1)
+ total_pages_state = gr.State(value=1)
+ per_page = 10 # Number of prompts per page
+
with gr.TabItem("Add & Edit Prompts", visible=True):
with gr.Row():
with gr.Column():
@@ -207,38 +212,145 @@ def create_prompt_edit_tab():
choices=[],
interactive=True
)
+ next_page_button = gr.Button("Next Page", visible=False)
+ page_display = gr.Markdown("Page 1 of X", visible=False)
+ prev_page_button = gr.Button("Previous Page", visible=False)
prompt_list_button = gr.Button("List Prompts")
with gr.Column():
title_input = gr.Textbox(label="Title", placeholder="Enter the prompt title")
- author_input = gr.Textbox(label="Author", placeholder="Enter the prompt's author", lines=3)
+ author_input = gr.Textbox(label="Author", placeholder="Enter the prompt's author", lines=1)
description_input = gr.Textbox(label="Description", placeholder="Enter the prompt description", lines=3)
system_prompt_input = gr.Textbox(label="System Prompt", placeholder="Enter the system prompt", lines=3)
user_prompt_input = gr.Textbox(label="User Prompt", placeholder="Enter the user prompt", lines=3)
add_prompt_button = gr.Button("Add/Update Prompt")
add_prompt_output = gr.HTML()
- # Event handlers
+ # Function to update the prompt dropdown with pagination
+ def update_prompt_dropdown(page=1):
+ prompts, total_pages, current_page = list_prompts(page=page, per_page=per_page)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ prev_button_visible = current_page > 1
+ next_button_visible = current_page < total_pages
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text, visible=True),
+ gr.update(visible=prev_button_visible),
+ gr.update(visible=next_button_visible),
+ current_page,
+ total_pages
+ )
+
+ # Event handler for listing prompts
prompt_list_button.click(
fn=update_prompt_dropdown,
- outputs=prompt_dropdown
+ inputs=[],
+ outputs=[
+ prompt_dropdown,
+ page_display,
+ prev_page_button,
+ next_page_button,
+ current_page_state,
+ total_pages_state
+ ]
+ )
+
+ # Functions to handle pagination
+ def on_prev_page_click(current_page):
+ new_page = max(current_page - 1, 1)
+ return update_prompt_dropdown(page=new_page)
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ return update_prompt_dropdown(page=new_page)
+
+ # Event handlers for pagination buttons
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state],
+ outputs=[
+ prompt_dropdown,
+ page_display,
+ prev_page_button,
+ next_page_button,
+ current_page_state,
+ total_pages_state
+ ]
+ )
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[
+ prompt_dropdown,
+ page_display,
+ prev_page_button,
+ next_page_button,
+ current_page_state,
+ total_pages_state
+ ]
)
+ # Event handler for adding or updating a prompt
add_prompt_button.click(
fn=add_or_update_prompt,
inputs=[title_input, author_input, description_input, system_prompt_input, user_prompt_input],
- outputs=add_prompt_output
+ outputs=[add_prompt_output]
+ ).then(
+ fn=update_prompt_dropdown,
+ inputs=[],
+ outputs=[
+ prompt_dropdown,
+ page_display,
+ prev_page_button,
+ next_page_button,
+ current_page_state,
+ total_pages_state
+ ]
)
- # Load prompt details when selected
+ # Function to load prompt details when a prompt is selected
+ def load_prompt_details(selected_prompt):
+ details = fetch_prompt_details(selected_prompt)
+ if details:
+ title, author, description, system_prompt, user_prompt, keywords = details
+ return (
+ gr.update(value=title),
+ gr.update(value=author or ""),
+ gr.update(value=description or ""),
+ gr.update(value=system_prompt or ""),
+ gr.update(value=user_prompt or "")
+ )
+ else:
+ return (
+ gr.update(value=""),
+ gr.update(value=""),
+ gr.update(value=""),
+ gr.update(value=""),
+ gr.update(value="")
+ )
+
+ # Event handler for prompt selection change
prompt_dropdown.change(
fn=load_prompt_details,
inputs=[prompt_dropdown],
- outputs=[title_input, author_input, system_prompt_input, user_prompt_input]
+ outputs=[
+ title_input,
+ author_input,
+ description_input,
+ system_prompt_input,
+ user_prompt_input
+ ]
)
+
def create_prompt_clone_tab():
+ # Initialize state variables for pagination
+ current_page_state = gr.State(value=1)
+ total_pages_state = gr.State(value=1)
+ per_page = 10 # Number of prompts per page
+
with gr.TabItem("Clone and Edit Prompts", visible=True):
with gr.Row():
with gr.Column():
@@ -248,6 +360,9 @@ def create_prompt_clone_tab():
choices=[],
interactive=True
)
+ next_page_button = gr.Button("Next Page", visible=False)
+ page_display = gr.Markdown("Page 1 of X", visible=False)
+ prev_page_button = gr.Button("Previous Page", visible=False)
prompt_list_button = gr.Button("List Prompts")
with gr.Column():
@@ -260,19 +375,99 @@ def create_prompt_clone_tab():
save_cloned_prompt_button = gr.Button("Save Cloned Prompt", visible=False)
add_prompt_output = gr.HTML()
- # Event handlers
+ # Function to update the prompt dropdown with pagination
+ def update_prompt_dropdown(page=1):
+ prompts, total_pages, current_page = list_prompts(page=page, per_page=per_page)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ prev_button_visible = current_page > 1
+ next_button_visible = current_page < total_pages
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text, visible=True),
+ gr.update(visible=prev_button_visible),
+ gr.update(visible=next_button_visible),
+ current_page,
+ total_pages
+ )
+
+ # Event handler for listing prompts
prompt_list_button.click(
fn=update_prompt_dropdown,
- outputs=prompt_dropdown
+ inputs=[],
+ outputs=[
+ prompt_dropdown,
+ page_display,
+ prev_page_button,
+ next_page_button,
+ current_page_state,
+ total_pages_state
+ ]
+ )
+
+ # Functions to handle pagination
+ def on_prev_page_click(current_page):
+ new_page = max(current_page - 1, 1)
+ return update_prompt_dropdown(page=new_page)
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ return update_prompt_dropdown(page=new_page)
+
+ # Event handlers for pagination buttons
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state],
+ outputs=[
+ prompt_dropdown,
+ page_display,
+ prev_page_button,
+ next_page_button,
+ current_page_state,
+ total_pages_state
+ ]
+ )
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[
+ prompt_dropdown,
+ page_display,
+ prev_page_button,
+ next_page_button,
+ current_page_state,
+ total_pages_state
+ ]
)
# Load prompt details when selected
+ def load_prompt_details(selected_prompt):
+ if selected_prompt:
+ details = fetch_prompt_details(selected_prompt)
+ if details:
+ title, author, description, system_prompt, user_prompt, keywords = details
+ return (
+ gr.update(value=title),
+ gr.update(value=author or ""),
+ gr.update(value=description or ""),
+ gr.update(value=system_prompt or ""),
+ gr.update(value=user_prompt or "")
+ )
+ return (
+ gr.update(value=""),
+ gr.update(value=""),
+ gr.update(value=""),
+ gr.update(value=""),
+ gr.update(value="")
+ )
+
prompt_dropdown.change(
fn=load_prompt_details,
inputs=[prompt_dropdown],
outputs=[title_input, author_input, description_input, system_prompt_input, user_prompt_input]
)
+ # Prepare for cloning
def prepare_for_cloning(selected_prompt):
if selected_prompt:
return gr.update(value=f"Copy of {selected_prompt}"), gr.update(visible=True)
@@ -284,18 +479,21 @@ def prepare_for_cloning(selected_prompt):
outputs=[title_input, save_cloned_prompt_button]
)
- def save_cloned_prompt(title, description, system_prompt, user_prompt):
+ # Function to save cloned prompt
+ def save_cloned_prompt(title, author, description, system_prompt, user_prompt, current_page):
try:
- result = add_prompt(title, description, system_prompt, user_prompt)
+ result = add_prompt(title, author, description, system_prompt, user_prompt)
if result == "Prompt added successfully.":
- return result, gr.update(choices=update_prompt_dropdown())
+ # After adding, refresh the prompt dropdown
+ prompt_dropdown_update = update_prompt_dropdown(page=current_page)
+ return (result, *prompt_dropdown_update)
else:
- return result, gr.update()
+ return (result, gr.update(), gr.update(), gr.update(), gr.update(), current_page, total_pages_state.value)
except Exception as e:
- return f"Error saving cloned prompt: {str(e)}", gr.update()
+ return (f"Error saving cloned prompt: {str(e)}", gr.update(), gr.update(), gr.update(), gr.update(), current_page, total_pages_state.value)
save_cloned_prompt_button.click(
fn=save_cloned_prompt,
- inputs=[title_input, description_input, system_prompt_input, user_prompt_input],
- outputs=[add_prompt_output, prompt_dropdown]
- )
\ No newline at end of file
+ inputs=[title_input, author_input, description_input, system_prompt_input, user_prompt_input, current_page_state],
+ outputs=[add_prompt_output, prompt_dropdown, page_display, prev_page_button, next_page_button, current_page_state, total_pages_state]
+ )
diff --git a/App_Function_Libraries/Gradio_UI/PDF_ingestion_tab.py b/App_Function_Libraries/Gradio_UI/PDF_ingestion_tab.py
index 0ccc391b9..04381ab13 100644
--- a/App_Function_Libraries/Gradio_UI/PDF_ingestion_tab.py
+++ b/App_Function_Libraries/Gradio_UI/PDF_ingestion_tab.py
@@ -10,7 +10,7 @@
import gradio as gr
#
# Local Imports
-from App_Function_Libraries.DB.DB_Manager import load_preset_prompts
+from App_Function_Libraries.DB.DB_Manager import list_prompts
from App_Function_Libraries.Gradio_UI.Chat_ui import update_user_prompt
from App_Function_Libraries.PDF.PDF_Ingestion_Lib import extract_metadata_from_pdf, extract_text_and_format_from_pdf, \
process_and_cleanup_pdf
@@ -39,78 +39,132 @@ def create_pdf_ingestion_tab():
)
# Common metadata for all files
pdf_keywords_input = gr.Textbox(label="Keywords (Optional, comma-separated)")
- with gr.Row():
- custom_prompt_checkbox = gr.Checkbox(
- label="Use a Custom Prompt",
- value=False,
- visible=True
- )
- preset_prompt_checkbox = gr.Checkbox(
- label="Use a pre-set Prompt",
- value=False,
- visible=True
- )
- with gr.Row():
- preset_prompt = gr.Dropdown(
- label="Select Preset Prompt",
- choices=load_preset_prompts(),
- visible=False
- )
- with gr.Row():
- custom_prompt_input = gr.Textbox(
- label="Custom Prompt",
- placeholder="Enter custom prompt here",
- lines=3,
- visible=False
- )
- with gr.Row():
- system_prompt_input = gr.Textbox(
- label="System Prompt",
- value="""
-You are a bulleted notes specialist.
-[INST]```When creating comprehensive bulleted notes, you should follow these guidelines: Use multiple headings based on the referenced topics, not categories like quotes or terms. Headings should be surrounded by bold formatting and not be listed as bullet points themselves. Leave no space between headings and their corresponding list items underneath. Important terms within the content should be emphasized by setting them in bold font. Any text that ends with a colon should also be bolded. Before submitting your response, review the instructions, and make any corrections necessary to adhered to the specified format. Do not reference these instructions within the notes.``` \nBased on the content between backticks create comprehensive bulleted notes.[/INST]
-**Bulleted Note Creation Guidelines**
-
-**Headings**:
-- Based on referenced topics, not categories like quotes or terms
-- Surrounded by **bold** formatting
-- Not listed as bullet points
-- No space between headings and list items underneath
-
-**Emphasis**:
-- **Important terms** set in bold font
-- **Text ending in a colon**: also bolded
-
-**Review**:
-- Ensure adherence to specified format
-- Do not reference these instructions in your response.[INST] {{ .Prompt }} [/INST]""",
- lines=3,
- visible=False
- )
-
- custom_prompt_checkbox.change(
- fn=lambda x: (gr.update(visible=x), gr.update(visible=x)),
- inputs=[custom_prompt_checkbox],
- outputs=[custom_prompt_input, system_prompt_input]
- )
- preset_prompt_checkbox.change(
- fn=lambda x: gr.update(visible=x),
- inputs=[preset_prompt_checkbox],
- outputs=[preset_prompt]
- )
-
- def update_prompts(preset_name):
- prompts = update_user_prompt(preset_name)
- return (
- gr.update(value=prompts["user_prompt"], visible=True),
- gr.update(value=prompts["system_prompt"], visible=True)
- )
-
- preset_prompt.change(
- update_prompts,
- inputs=preset_prompt,
- outputs=[custom_prompt_input, system_prompt_input]
- )
+# with gr.Row():
+# custom_prompt_checkbox = gr.Checkbox(
+# label="Use a Custom Prompt",
+# value=False,
+# visible=True
+# )
+# preset_prompt_checkbox = gr.Checkbox(
+# label="Use a pre-set Prompt",
+# value=False,
+# visible=True
+# )
+# # Initialize state variables for pagination
+# current_page_state = gr.State(value=1)
+# total_pages_state = gr.State(value=1)
+# with gr.Row():
+# # Add pagination controls
+# preset_prompt = gr.Dropdown(
+# label="Select Preset Prompt",
+# choices=[],
+# visible=False
+# )
+# prev_page_button = gr.Button("Previous Page", visible=False)
+# page_display = gr.Markdown("Page 1 of X", visible=False)
+# next_page_button = gr.Button("Next Page", visible=False)
+# with gr.Row():
+# custom_prompt_input = gr.Textbox(
+# label="Custom Prompt",
+# placeholder="Enter custom prompt here",
+# lines=3,
+# visible=False
+# )
+# with gr.Row():
+# system_prompt_input = gr.Textbox(
+# label="System Prompt",
+# value="""
+# You are a bulleted notes specialist.
+# [INST]```When creating comprehensive bulleted notes, you should follow these guidelines: Use multiple headings based on the referenced topics, not categories like quotes or terms. Headings should be surrounded by bold formatting and not be listed as bullet points themselves. Leave no space between headings and their corresponding list items underneath. Important terms within the content should be emphasized by setting them in bold font. Any text that ends with a colon should also be bolded. Before submitting your response, review the instructions, and make any corrections necessary to adhered to the specified format. Do not reference these instructions within the notes.``` \nBased on the content between backticks create comprehensive bulleted notes.[/INST]
+# **Bulleted Note Creation Guidelines**
+#
+# **Headings**:
+# - Based on referenced topics, not categories like quotes or terms
+# - Surrounded by **bold** formatting
+# - Not listed as bullet points
+# - No space between headings and list items underneath
+#
+# **Emphasis**:
+# - **Important terms** set in bold font
+# - **Text ending in a colon**: also bolded
+#
+# **Review**:
+# - Ensure adherence to specified format
+# - Do not reference these instructions in your response.[INST] {{ .Prompt }} [/INST]""",
+# lines=3,
+# visible=False
+# )
+#
+# custom_prompt_checkbox.change(
+# fn=lambda x: (gr.update(visible=x), gr.update(visible=x)),
+# inputs=[custom_prompt_checkbox],
+# outputs=[custom_prompt_input, system_prompt_input]
+# )
+#
+# def on_preset_prompt_checkbox_change(is_checked):
+# if is_checked:
+# prompts, total_pages, current_page = list_prompts(page=1, per_page=10)
+# page_display_text = f"Page {current_page} of {total_pages}"
+# return (
+# gr.update(visible=True, interactive=True, choices=prompts), # preset_prompt
+# gr.update(visible=True), # prev_page_button
+# gr.update(visible=True), # next_page_button
+# gr.update(value=page_display_text, visible=True), # page_display
+# current_page, # current_page_state
+# total_pages # total_pages_state
+# )
+# else:
+# return (
+# gr.update(visible=False, interactive=False), # preset_prompt
+# gr.update(visible=False), # prev_page_button
+# gr.update(visible=False), # next_page_button
+# gr.update(visible=False), # page_display
+# 1, # current_page_state
+# 1 # total_pages_state
+# )
+#
+# preset_prompt_checkbox.change(
+# fn=on_preset_prompt_checkbox_change,
+# inputs=[preset_prompt_checkbox],
+# outputs=[preset_prompt, prev_page_button, next_page_button, page_display, current_page_state, total_pages_state]
+# )
+#
+# def on_prev_page_click(current_page, total_pages):
+# new_page = max(current_page - 1, 1)
+# prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+# page_display_text = f"Page {current_page} of {total_pages}"
+# return gr.update(choices=prompts), gr.update(value=page_display_text), current_page
+#
+# prev_page_button.click(
+# fn=on_prev_page_click,
+# inputs=[current_page_state, total_pages_state],
+# outputs=[preset_prompt, page_display, current_page_state]
+# )
+#
+# def on_next_page_click(current_page, total_pages):
+# new_page = min(current_page + 1, total_pages)
+# prompts, total_pages, current_page = list_prompts(page=new_page, per_page=10)
+# page_display_text = f"Page {current_page} of {total_pages}"
+# return gr.update(choices=prompts), gr.update(value=page_display_text), current_page
+#
+# next_page_button.click(
+# fn=on_next_page_click,
+# inputs=[current_page_state, total_pages_state],
+# outputs=[preset_prompt, page_display, current_page_state]
+# )
+#
+# def update_prompts(preset_name):
+# prompts = update_user_prompt(preset_name)
+# return (
+# gr.update(value=prompts["user_prompt"], visible=True),
+# gr.update(value=prompts["system_prompt"], visible=True)
+# )
+#
+# preset_prompt.change(
+# update_prompts,
+# inputs=preset_prompt,
+# outputs=[custom_prompt_input, system_prompt_input]
+# )
pdf_ingest_button = gr.Button("Ingest PDFs")
@@ -128,7 +182,7 @@ def update_prompts(preset_name):
)
# Define a new function to handle multiple PDFs
- def process_multiple_pdfs(pdf_files, keywords):
+ def process_multiple_pdfs(pdf_files, keywords, custom_prompt_checkbox_value, custom_prompt_text, system_prompt_text):
results = []
if pdf_files is None:
return [["No files", "Error", "No files uploaded"]]
@@ -138,12 +192,22 @@ def process_multiple_pdfs(pdf_files, keywords):
# Extract metadata from PDF
metadata = extract_metadata_from_pdf(pdf_file.name)
- # Process the PDF
+ # Use custom or system prompt if checkbox is checked
+ if custom_prompt_checkbox_value:
+ prompt = custom_prompt_text
+ system_prompt = system_prompt_text
+ else:
+ prompt = None
+ system_prompt = None
+
+ # Process the PDF with prompts
result = process_and_cleanup_pdf(
pdf_file,
metadata.get('title', os.path.splitext(os.path.basename(pdf_file.name))[0]),
metadata.get('author', 'Unknown'),
- keywords
+ keywords,
+ #prompt=prompt,
+ #system_prompt=system_prompt
)
results.append([
@@ -163,7 +227,13 @@ def process_multiple_pdfs(pdf_files, keywords):
# Update the ingest button click handler
pdf_ingest_button.click(
fn=process_multiple_pdfs,
- inputs=[pdf_file_input, pdf_keywords_input],
+ inputs=[
+ pdf_file_input,
+ pdf_keywords_input,
+ #custom_prompt_checkbox,
+ #custom_prompt_input,
+ #system_prompt_input
+ ],
outputs=pdf_result_output
)
diff --git a/App_Function_Libraries/Gradio_UI/Podcast_tab.py b/App_Function_Libraries/Gradio_UI/Podcast_tab.py
index 2372c1277..84c68be86 100644
--- a/App_Function_Libraries/Gradio_UI/Podcast_tab.py
+++ b/App_Function_Libraries/Gradio_UI/Podcast_tab.py
@@ -2,25 +2,21 @@
# Description: Gradio UI for ingesting podcasts into the database
#
# Imports
+import logging
#
# External Imports
-import logging
-
import gradio as gr
#
# Local Imports
from App_Function_Libraries.Audio.Audio_Files import process_podcast
-from App_Function_Libraries.DB.DB_Manager import load_preset_prompts
+from App_Function_Libraries.DB.DB_Manager import list_prompts
from App_Function_Libraries.Gradio_UI.Gradio_Shared import whisper_models, update_user_prompt
from App_Function_Libraries.Utils.Utils import default_api_endpoint, global_api_endpoints, format_api_name
-
-
#
########################################################################################################################
#
# Functions:
-
def create_podcast_tab():
try:
default_value = None
@@ -34,6 +30,10 @@ def create_podcast_tab():
default_value = None
with gr.TabItem("Podcast", visible=True):
gr.Markdown("# Podcast Transcription and Ingestion", visible=True)
+ # Initialize state variables for pagination
+ current_page_state = gr.State(value=1)
+ total_pages_state = gr.State(value=1)
+
with gr.Row():
with gr.Column():
podcast_url_input = gr.Textbox(label="Podcast URL", placeholder="Enter the podcast URL here")
@@ -50,54 +50,130 @@ def create_podcast_tab():
keep_timestamps_input = gr.Checkbox(label="Keep Timestamps", value=True)
with gr.Row():
- podcast_custom_prompt_checkbox = gr.Checkbox(label="Use a Custom Prompt",
- value=False,
- visible=True)
- preset_prompt_checkbox = gr.Checkbox(label="Use a pre-set Prompt",
- value=False,
- visible=True)
+ podcast_custom_prompt_checkbox = gr.Checkbox(
+ label="Use a Custom Prompt",
+ value=False,
+ visible=True
+ )
+ preset_prompt_checkbox = gr.Checkbox(
+ label="Use a pre-set Prompt",
+ value=False,
+ visible=True
+ )
+
+ with gr.Row():
+ # Add pagination controls
+ preset_prompt = gr.Dropdown(
+ label="Select Preset Prompt",
+ choices=[],
+ visible=False
+ )
with gr.Row():
- preset_prompt = gr.Dropdown(label="Select Preset Prompt",
- choices=load_preset_prompts(),
- visible=False)
+ prev_page_button = gr.Button("Previous Page", visible=False)
+ page_display = gr.Markdown("Page 1 of X", visible=False)
+ next_page_button = gr.Button("Next Page", visible=False)
+
with gr.Row():
- podcast_custom_prompt_input = gr.Textbox(label="Custom Prompt",
- placeholder="Enter custom prompt here",
- lines=3,
- visible=False)
+ podcast_custom_prompt_input = gr.Textbox(
+ label="Custom Prompt",
+ placeholder="Enter custom prompt here",
+ lines=10,
+ visible=False
+ )
with gr.Row():
- system_prompt_input = gr.Textbox(label="System Prompt",
- value="""You are a bulleted notes specialist. [INST]```When creating comprehensive bulleted notes, you should follow these guidelines: Use multiple headings based on the referenced topics, not categories like quotes or terms. Headings should be surrounded by bold formatting and not be listed as bullet points themselves. Leave no space between headings and their corresponding list items underneath. Important terms within the content should be emphasized by setting them in bold font. Any text that ends with a colon should also be bolded. Before submitting your response, review the instructions, and make any corrections necessary to adhered to the specified format. Do not reference these instructions within the notes.``` \nBased on the content between backticks create comprehensive bulleted notes.[/INST]
-**Bulleted Note Creation Guidelines**
-
-**Headings**:
-- Based on referenced topics, not categories like quotes or terms
-- Surrounded by **bold** formatting
-- Not listed as bullet points
-- No space between headings and list items underneath
-
-**Emphasis**:
-- **Important terms** set in bold font
-- **Text ending in a colon**: also bolded
-
-**Review**:
-- Ensure adherence to specified format
-- Do not reference these instructions in your response.[INST] {{ .Prompt }} [/INST]
-""",
- lines=3,
- visible=False)
+ system_prompt_input = gr.Textbox(
+ label="System Prompt",
+ value="""You are a bulleted notes specialist. [INST]```When creating comprehensive bulleted notes, you should follow these guidelines: Use multiple headings based on the referenced topics, not categories like quotes or terms. Headings should be surrounded by bold formatting and not be listed as bullet points themselves. Leave no space between headings and their corresponding list items underneath. Important terms within the content should be emphasized by setting them in bold font. Any text that ends with a colon should also be bolded. Before submitting your response, review the instructions, and make any corrections necessary to adhere to the specified format. Do not reference these instructions within the notes.``` \nBased on the content between backticks create comprehensive bulleted notes.[/INST]
+ **Bulleted Note Creation Guidelines**
+
+ **Headings**:
+ - Based on referenced topics, not categories like quotes or terms
+ - Surrounded by **bold** formatting
+ - Not listed as bullet points
+ - No space between headings and list items underneath
+
+ **Emphasis**:
+ - **Important terms** set in bold font
+ - **Text ending in a colon**: also bolded
+ **Review**:
+ - Ensure adherence to specified format
+ - Do not reference these instructions in your response.[INST] {{ .Prompt }} [/INST]
+ """,
+ lines=10,
+ visible=False
+ )
+
+ # Handle custom prompt checkbox change
podcast_custom_prompt_checkbox.change(
fn=lambda x: (gr.update(visible=x), gr.update(visible=x)),
inputs=[podcast_custom_prompt_checkbox],
outputs=[podcast_custom_prompt_input, system_prompt_input]
)
+
+ # Handle preset prompt checkbox change
+ def on_preset_prompt_checkbox_change(is_checked):
+ if is_checked:
+ prompts, total_pages, current_page = list_prompts(page=1, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(visible=True, interactive=True, choices=prompts), # preset_prompt
+ gr.update(visible=True), # prev_page_button
+ gr.update(visible=True), # next_page_button
+ gr.update(value=page_display_text, visible=True), # page_display
+ current_page, # current_page_state
+ total_pages # total_pages_state
+ )
+ else:
+ return (
+ gr.update(visible=False, interactive=False), # preset_prompt
+ gr.update(visible=False), # prev_page_button
+ gr.update(visible=False), # next_page_button
+ gr.update(visible=False), # page_display
+ 1, # current_page_state
+ 1 # total_pages_state
+ )
+
preset_prompt_checkbox.change(
- fn=lambda x: gr.update(visible=x),
+ fn=on_preset_prompt_checkbox_change,
inputs=[preset_prompt_checkbox],
- outputs=[preset_prompt]
+ outputs=[preset_prompt, prev_page_button, next_page_button, page_display, current_page_state, total_pages_state]
+ )
+
+ # Pagination button functions
+ def on_prev_page_click(current_page, total_pages):
+ new_page = max(current_page - 1, 1)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ prev_page_button.click(
+ fn=on_prev_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
+ )
+
+ def on_next_page_click(current_page, total_pages):
+ new_page = min(current_page + 1, total_pages)
+ prompts, total_pages, current_page = list_prompts(page=new_page, per_page=20)
+ page_display_text = f"Page {current_page} of {total_pages}"
+ return (
+ gr.update(choices=prompts),
+ gr.update(value=page_display_text),
+ current_page
+ )
+
+ next_page_button.click(
+ fn=on_next_page_click,
+ inputs=[current_page_state, total_pages_state],
+ outputs=[preset_prompt, page_display, current_page_state]
)
+ # Update prompts when a preset is selected
def update_prompts(preset_name):
prompts = update_user_prompt(preset_name)
return (
@@ -106,8 +182,8 @@ def update_prompts(preset_name):
)
preset_prompt.change(
- update_prompts,
- inputs=preset_prompt,
+ fn=update_prompts,
+ inputs=[preset_prompt],
outputs=[podcast_custom_prompt_input, system_prompt_input]
)
@@ -166,13 +242,37 @@ def update_prompts(preset_name):
podcast_process_button.click(
fn=process_podcast,
- inputs=[podcast_url_input, podcast_title_input, podcast_author_input,
- podcast_keywords_input, podcast_custom_prompt_input, podcast_api_name_input,
- podcast_api_key_input, podcast_whisper_model_input, keep_original_input,
- enable_diarization_input, use_cookies_input, cookies_input,
- chunk_method, max_chunk_size, chunk_overlap, use_adaptive_chunking,
- use_multi_level_chunking, chunk_language, keep_timestamps_input],
- outputs=[podcast_progress_output, podcast_transcription_output, podcast_summary_output,
- podcast_title_input, podcast_author_input, podcast_keywords_input, podcast_error_output,
- download_transcription, download_summary]
+ inputs=[
+ podcast_url_input,
+ podcast_title_input,
+ podcast_author_input,
+ podcast_keywords_input,
+ podcast_custom_prompt_input,
+ podcast_api_name_input,
+ podcast_api_key_input,
+ podcast_whisper_model_input,
+ keep_original_input,
+ enable_diarization_input,
+ use_cookies_input,
+ cookies_input,
+ chunk_method,
+ max_chunk_size,
+ chunk_overlap,
+ use_adaptive_chunking,
+ use_multi_level_chunking,
+ chunk_language,
+ keep_timestamps_input,
+ system_prompt_input # Include system prompt input
+ ],
+ outputs=[
+ podcast_progress_output,
+ podcast_transcription_output,
+ podcast_summary_output,
+ podcast_title_input,
+ podcast_author_input,
+ podcast_keywords_input,
+ podcast_error_output,
+ download_transcription,
+ download_summary
+ ]
)
\ No newline at end of file
diff --git a/App_Function_Libraries/Gradio_UI/Prompts_tab.py b/App_Function_Libraries/Gradio_UI/Prompts_tab.py
index f24879bd0..dedfcf9d9 100644
--- a/App_Function_Libraries/Gradio_UI/Prompts_tab.py
+++ b/App_Function_Libraries/Gradio_UI/Prompts_tab.py
@@ -10,7 +10,7 @@
import gradio as gr
#
# Local Imports
-from App_Function_Libraries.DB.DB_Manager import fetch_prompt_details, list_prompts, load_preset_prompts
+from App_Function_Libraries.DB.DB_Manager import fetch_prompt_details, list_prompts
#
####################################################################################################
#
@@ -24,17 +24,19 @@ def create_prompt_view_tab():
entries_per_page = gr.Dropdown(choices=[10, 20, 50, 100], label="Entries per Page", value=10)
page_number = gr.Number(value=1, label="Page Number", precision=0)
view_button = gr.Button("View Page")
- next_page_button = gr.Button("Next Page")
- previous_page_button = gr.Button("Previous Page")
+ previous_page_button = gr.Button("Previous Page", visible=True)
+ next_page_button = gr.Button("Next Page", visible=True)
pagination_info = gr.Textbox(label="Pagination Info", interactive=False)
prompt_selector = gr.Dropdown(label="Select Prompt to View", choices=[])
with gr.Column():
results_table = gr.HTML()
selected_prompt_display = gr.HTML()
+ # Function to view database entries
def view_database(page, entries_per_page):
try:
- prompts, total_pages, current_page = list_prompts(page, entries_per_page)
+ # Use list_prompts to get prompts and total pages
+ prompts, total_pages, current_page = list_prompts(page=int(page), per_page=int(entries_per_page))
table_html = "
Title | Author |
---|---|
{html.escape(title)} | {html.escape(author)} |
Error fetching prompts: {e}
", "Error", 0, [] + # Function to update page content def update_page(page, entries_per_page): results, pagination, total_pages, prompt_choices = view_database(page, entries_per_page) + page = int(page) next_disabled = page >= total_pages prev_disabled = page <= 1 - return results, pagination, page, gr.update(interactive=not next_disabled), gr.update( - interactive=not prev_disabled), gr.update(choices=prompt_choices) - + return ( + results, + pagination, + page, + gr.update(visible=True, interactive=not prev_disabled), # previous_page_button + gr.update(visible=True, interactive=not next_disabled), # next_page_button + gr.update(choices=prompt_choices) + ) + + # Function to go to the next page def go_to_next_page(current_page, entries_per_page): - next_page = current_page + 1 + next_page = int(current_page) + 1 return update_page(next_page, entries_per_page) + # Function to go to the previous page def go_to_previous_page(current_page, entries_per_page): - previous_page = max(1, current_page - 1) + previous_page = max(1, int(current_page) - 1) return update_page(previous_page, entries_per_page) + # Function to display selected prompt details def display_selected_prompt(prompt_name): details = fetch_prompt_details(prompt_name) if details: @@ -100,25 +115,23 @@ def display_selected_prompt(prompt_name): else: return "Prompt not found.
" + # Event handlers view_button.click( fn=update_page, inputs=[page_number, entries_per_page], - outputs=[results_table, pagination_info, page_number, next_page_button, previous_page_button, - prompt_selector] + outputs=[results_table, pagination_info, page_number, previous_page_button, next_page_button, prompt_selector] ) next_page_button.click( fn=go_to_next_page, inputs=[page_number, entries_per_page], - outputs=[results_table, pagination_info, page_number, next_page_button, previous_page_button, - prompt_selector] + outputs=[results_table, pagination_info, page_number, previous_page_button, next_page_button, prompt_selector] ) previous_page_button.click( fn=go_to_previous_page, inputs=[page_number, entries_per_page], - outputs=[results_table, pagination_info, page_number, next_page_button, previous_page_button, - prompt_selector] + outputs=[results_table, pagination_info, page_number, previous_page_button, next_page_button, prompt_selector] ) prompt_selector.change( @@ -128,6 +141,7 @@ def display_selected_prompt(prompt_name): ) + def create_prompts_export_tab(): """Creates a tab for exporting prompts database content with multiple format options""" with gr.TabItem("Export Prompts", visible=True): diff --git a/App_Function_Libraries/Gradio_UI/RAG_QA_Chat_tab.py b/App_Function_Libraries/Gradio_UI/RAG_QA_Chat_tab.py index 28ff2363a..0c88aaeb3 100644 --- a/App_Function_Libraries/Gradio_UI/RAG_QA_Chat_tab.py +++ b/App_Function_Libraries/Gradio_UI/RAG_QA_Chat_tab.py @@ -21,7 +21,7 @@ clear_keywords_from_note, add_keywords_to_note, load_chat_history, save_message, add_keywords_to_conversation, \ get_keywords_for_note, delete_note, search_conversations_by_keywords, get_conversation_title, delete_conversation, \ update_conversation_title, fetch_all_conversations, fetch_all_notes, fetch_conversations_by_ids, fetch_notes_by_ids, \ - search_media_db, load_preset_prompts, search_notes_titles + search_media_db, search_notes_titles, list_prompts from App_Function_Libraries.DB.RAG_QA_Chat_DB import get_notes, delete_messages_in_conversation, search_rag_notes, \ search_rag_chat, get_conversation_rating, set_conversation_rating from App_Function_Libraries.Gradio_UI.Gradio_Shared import update_user_prompt @@ -124,14 +124,24 @@ def update_conversation_list(): value=auto_save_value, info="When enabled, conversations will be saved automatically after each message" ) + + initial_prompts, total_pages, current_page = list_prompts(page=1, per_page=10) + preset_prompt_checkbox = gr.Checkbox( label="View Custom Prompts(have to copy/paste them)", value=False, visible=True ) + + with gr.Row(visible=False) as preset_prompt_controls: + prev_prompt_page = gr.Button("Previous") + current_prompt_page_text = gr.Text(f"Page {current_page} of {total_pages}") + next_prompt_page = gr.Button("Next") + current_prompt_page_state = gr.State(value=1) + preset_prompt = gr.Dropdown( label="Select Preset Prompt", - choices=load_preset_prompts(), + choices=initial_prompts, visible=False ) user_prompt = gr.Textbox( @@ -140,22 +150,16 @@ def update_conversation_list(): lines=3, visible=False ) + system_prompt_input = gr.Textbox( label="System Prompt", lines=3, visible=False ) - # with gr.Row(): - # page_number = gr.Number(value=1, label="Page", precision=0) - # page_size = gr.Number(value=20, label="Items per page", precision=0) - # total_pages = gr.Number(label="Total Pages", interactive=False) - - search_query = gr.Textbox(label="Search Query", visible=False) search_button = gr.Button("Search", visible=False) search_results = gr.Dropdown(label="Search Results", choices=[], visible=False) - # FIXME - Add pages for search results handling file_upload = gr.File( label="Upload File", visible=False, @@ -225,6 +229,15 @@ def update_conversation_list(): # Function Definitions + def update_prompt_page(direction, current_page_val): + new_page = max(1, min(total_pages, current_page_val + direction)) + prompts, _, _ = list_prompts(page=new_page, per_page=10) + return ( + gr.update(choices=prompts), + gr.update(value=f"Page {new_page} of {total_pages}"), + new_page + ) + def update_prompts(preset_name): prompts = update_user_prompt(preset_name) return ( @@ -234,11 +247,24 @@ def update_prompts(preset_name): def toggle_preset_prompt(checkbox_value): return ( - gr.update(visible=checkbox_value), # preset_prompt dropdown - gr.update(visible=False), # user_prompt - gr.update(visible=False) # system_prompt_input + gr.update(visible=checkbox_value), + gr.update(visible=checkbox_value), + gr.update(visible=False), + gr.update(visible=False) ) + prev_prompt_page.click( + lambda x: update_prompt_page(-1, x), + inputs=[current_prompt_page_state], + outputs=[preset_prompt, current_prompt_page_text, current_prompt_page_state] + ) + + next_prompt_page.click( + lambda x: update_prompt_page(1, x), + inputs=[current_prompt_page_state], + outputs=[preset_prompt, current_prompt_page_text, current_prompt_page_state] + ) + preset_prompt.change( update_prompts, inputs=preset_prompt, @@ -248,7 +274,7 @@ def toggle_preset_prompt(checkbox_value): preset_prompt_checkbox.change( toggle_preset_prompt, inputs=[preset_prompt_checkbox], - outputs=[preset_prompt, user_prompt, system_prompt_input] + outputs=[preset_prompt, preset_prompt_controls, user_prompt, system_prompt_input] ) def update_state(state, **kwargs): @@ -894,7 +920,7 @@ def delete_selected_note(state_value): # Reset state state_value["selected_note_id"] = None # Update notes list - updated_notes = search_notes("") + updated_notes = search_notes("", "") return updated_notes, gr.update(value="Note deleted successfully."), state_value else: return gr.update(), gr.update(value="No note selected."), state_value diff --git a/App_Function_Libraries/Gradio_UI/Re_summarize_tab.py b/App_Function_Libraries/Gradio_UI/Re_summarize_tab.py index f0181feda..ca9f33170 100644 --- a/App_Function_Libraries/Gradio_UI/Re_summarize_tab.py +++ b/App_Function_Libraries/Gradio_UI/Re_summarize_tab.py @@ -10,16 +10,13 @@ # # Local Imports from App_Function_Libraries.Chunk_Lib import improved_chunking_process -from App_Function_Libraries.DB.DB_Manager import update_media_content, load_preset_prompts +from App_Function_Libraries.DB.DB_Manager import update_media_content, list_prompts from App_Function_Libraries.Gradio_UI.Chat_ui import update_user_prompt from App_Function_Libraries.Gradio_UI.Gradio_Shared import fetch_item_details, fetch_items_by_keyword, \ fetch_items_by_content, fetch_items_by_title_or_url from App_Function_Libraries.Summarization.Summarization_General_Lib import summarize_chunk from App_Function_Libraries.Utils.Utils import load_comprehensive_config, default_api_endpoint, global_api_endpoints, \ format_api_name - - -# # ###################################################################################################################### # @@ -36,6 +33,10 @@ def create_resummary_tab(): except Exception as e: logging.error(f"Error setting default API endpoint: {str(e)}") default_value = None + + # Get initial prompts for first page + initial_prompts, total_pages, current_page = list_prompts(page=1, per_page=20) + with gr.TabItem("Re-Summarize", visible=True): gr.Markdown("# Re-Summarize Existing Content") with gr.Row(): @@ -48,7 +49,6 @@ def create_resummary_tab(): item_mapping = gr.State({}) with gr.Row(): - # Refactored API selection dropdown api_name_input = gr.Dropdown( choices=["None"] + [format_api_name(api) for api in global_api_endpoints], value=default_value, @@ -70,9 +70,17 @@ def create_resummary_tab(): preset_prompt_checkbox = gr.Checkbox(label="Use a pre-set Prompt", value=False, visible=True) + + # Add pagination controls for preset prompts + with gr.Row(visible=False) as preset_prompt_controls: + prev_page = gr.Button("Previous") + current_page_text = gr.Text(f"Page {current_page} of {total_pages}") + next_page = gr.Button("Next") + current_page_state = gr.State(value=1) + with gr.Row(): preset_prompt = gr.Dropdown(label="Select Preset Prompt", - choices=load_preset_prompts(), + choices=initial_prompts, visible=False) with gr.Row(): custom_prompt_input = gr.Textbox(label="Custom Prompt", @@ -101,6 +109,15 @@ def create_resummary_tab(): lines=3, visible=False) + def update_prompt_page(direction, current_page_val): + new_page = max(1, min(total_pages, current_page_val + direction)) + prompts, _, _ = list_prompts(page=new_page, per_page=10) + return ( + gr.update(choices=prompts), + gr.update(value=f"Page {new_page} of {total_pages}"), + new_page + ) + def update_prompts(preset_name): prompts = update_user_prompt(preset_name) return ( @@ -108,6 +125,19 @@ def update_prompts(preset_name): gr.update(value=prompts["system_prompt"], visible=True) ) + # Connect pagination buttons + prev_page.click( + lambda x: update_prompt_page(-1, x), + inputs=[current_page_state], + outputs=[preset_prompt, current_page_text, current_page_state] + ) + + next_page.click( + lambda x: update_prompt_page(1, x), + inputs=[current_page_state], + outputs=[preset_prompt, current_page_text, current_page_state] + ) + preset_prompt.change( update_prompts, inputs=preset_prompt, @@ -124,9 +154,9 @@ def update_prompts(preset_name): outputs=[custom_prompt_input, system_prompt_input] ) preset_prompt_checkbox.change( - fn=lambda x: gr.update(visible=x), + fn=lambda x: (gr.update(visible=x), gr.update(visible=x)), inputs=[preset_prompt_checkbox], - outputs=[preset_prompt] + outputs=[preset_prompt, preset_prompt_controls] ) # Connect the UI elements @@ -155,7 +185,12 @@ def update_prompts(preset_name): outputs=result_output ) - return search_query_input, search_type_input, search_button, items_output, item_mapping, api_name_input, api_key_input, chunking_options_checkbox, chunking_options_box, chunk_method, max_chunk_size, chunk_overlap, custom_prompt_checkbox, custom_prompt_input, resummarize_button, result_output + return ( + search_query_input, search_type_input, search_button, items_output, + item_mapping, api_name_input, api_key_input, chunking_options_checkbox, + chunking_options_box, chunk_method, max_chunk_size, chunk_overlap, + custom_prompt_checkbox, custom_prompt_input, resummarize_button, result_output + ) def update_resummarize_dropdown(search_query, search_type): diff --git a/App_Function_Libraries/Gradio_UI/Video_transcription_tab.py b/App_Function_Libraries/Gradio_UI/Video_transcription_tab.py index 7aa4e0d3a..3d03af228 100644 --- a/App_Function_Libraries/Gradio_UI/Video_transcription_tab.py +++ b/App_Function_Libraries/Gradio_UI/Video_transcription_tab.py @@ -14,8 +14,8 @@ from App_Function_Libraries.Chunk_Lib import improved_chunking_process # # Local Imports -from App_Function_Libraries.DB.DB_Manager import load_preset_prompts, add_media_to_database, \ - check_media_and_whisper_model, check_existing_media, update_media_content_with_version +from App_Function_Libraries.DB.DB_Manager import add_media_to_database, \ + check_media_and_whisper_model, check_existing_media, update_media_content_with_version, list_prompts from App_Function_Libraries.Gradio_UI.Gradio_Shared import whisper_models, update_user_prompt from App_Function_Libraries.Gradio_UI.Gradio_Shared import error_handler from App_Function_Libraries.Summarization.Summarization_General_Lib import perform_transcription, perform_summarization, \ @@ -67,15 +67,20 @@ def create_video_transcription_tab(): preset_prompt_checkbox = gr.Checkbox(label="Use a pre-set Prompt", value=False, visible=True) + + # Initialize state variables for pagination + current_page_state = gr.State(value=1) + total_pages_state = gr.State(value=1) + with gr.Row(): + # Add pagination controls preset_prompt = gr.Dropdown(label="Select Preset Prompt", - choices=load_preset_prompts(), + choices=[], visible=False) with gr.Row(): - custom_prompt_input = gr.Textbox(label="Custom Prompt", - placeholder="Enter custom prompt here", - lines=3, - visible=False) + prev_page_button = gr.Button("Previous Page", visible=False) + page_display = gr.Markdown("Page 1 of X", visible=False) + next_page_button = gr.Button("Next Page", visible=False) with gr.Row(): system_prompt_input = gr.Textbox(label="System Prompt", value="""