Spaces:
Running
Running
File size: 6,992 Bytes
43cd37c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# View_tab.py
# Description: Gradio functions for the view tab
#
# Imports
#
# External Imports
import gradio as gr
#
# Local Imports
from App_Function_Libraries.DB.DB_Manager import (
search_media_database, mark_as_trash, get_specific_prompt, delete_specific_transcript,
delete_specific_summary, delete_specific_prompt, get_specific_transcript, get_specific_summary,
get_media_transcripts, get_media_summaries, get_media_prompts
)
#
############################################################################################################
#
# Functions:
# FIXME - add mark_as_trash ability to the UI
# FIXME - Doesn't work. also need ot merge this tab wtih Edit Existing Items tab....
def create_manage_items_tab():
with gr.TabItem("Edit/Manage DB Items", visible=True):
search_input = gr.Textbox(label="Search for Media (title or ID)")
search_button = gr.Button("Search")
media_selector = gr.Dropdown(label="Select Media", choices=[], interactive=True)
with gr.Accordion("Transcripts"):
get_transcripts_button = gr.Button("Get Transcripts")
transcript_selector = gr.Dropdown(label="Select Transcript", choices=[], interactive=True)
transcripts_output = gr.Textbox(label="Transcript Content", lines=10)
delete_transcript_button = gr.Button("Delete Selected Transcript")
with gr.Accordion("Summaries"):
get_summaries_button = gr.Button("Get Summaries")
summary_selector = gr.Dropdown(label="Select Summary", choices=[], interactive=True)
summaries_output = gr.Textbox(label="Summary Content", lines=5)
delete_summary_button = gr.Button("Delete Selected Summary")
with gr.Accordion("Prompts"):
get_prompts_button = gr.Button("Get Prompts")
prompt_selector = gr.Dropdown(label="Select Prompt", choices=[], interactive=True)
prompts_output = gr.Textbox(label="Prompt Content", lines=5)
delete_prompt_button = gr.Button("Delete Selected Prompt")
status_output = gr.Textbox(label="Status")
def search_media(query):
results = search_media_database(query)
choices = [f"{result[0]}: {result[1]}" for result in results]
return {"choices": choices, "value": None}
search_button.click(search_media, inputs=[search_input], outputs=[media_selector])
def get_transcripts(media_selection):
if not media_selection:
return {"choices": [], "value": None}
media_id = int(media_selection.split(":")[0])
transcripts = get_media_transcripts(media_id)
choices = [f"{t[0]}: {t[3]}" for t in transcripts]
return {"choices": choices, "value": None}
def display_transcript(transcript_selection):
if not transcript_selection:
return "No transcript selected."
transcript_id = int(transcript_selection.split(":")[0])
transcript = get_specific_transcript(transcript_id)
return transcript['content'] if 'content' in transcript else transcript.get('error', "Transcript not found.")
get_transcripts_button.click(
get_transcripts,
inputs=[media_selector],
outputs=[transcript_selector]
)
transcript_selector.change(
display_transcript,
inputs=[transcript_selector],
outputs=[transcripts_output]
)
def get_summaries(media_selection):
if not media_selection:
return {"choices": [], "value": None}
media_id = int(media_selection.split(":")[0])
summaries = get_media_summaries(media_id)
choices = [f"{s[0]}: {s[3]}" for s in summaries]
return {"choices": choices, "value": None}
def display_summary(summary_selection):
if not summary_selection:
return "No summary selected."
summary_id = int(summary_selection.split(":")[0])
summary = get_specific_summary(summary_id)
return summary['content'] if 'content' in summary else summary.get('error', "Summary not found.")
get_summaries_button.click(
get_summaries,
inputs=[media_selector],
outputs=[summary_selector]
)
summary_selector.change(
display_summary,
inputs=[summary_selector],
outputs=[summaries_output]
)
def get_prompts(media_selection):
if not media_selection:
return {"choices": [], "value": None}
media_id = int(media_selection.split(":")[0])
prompts = get_media_prompts(media_id)
choices = [f"{p[0]}: {p[3]}" for p in prompts]
return {"choices": choices, "value": None}
def display_prompt(prompt_selection):
if not prompt_selection:
return "No prompt selected."
prompt_id = int(prompt_selection.split(":")[0])
prompt = get_specific_prompt(prompt_id)
return prompt['content'] if 'content' in prompt else prompt.get('error', "Prompt not found.")
get_prompts_button.click(
get_prompts,
inputs=[media_selector],
outputs=[prompt_selector]
)
prompt_selector.change(
display_prompt,
inputs=[prompt_selector],
outputs=[prompts_output]
)
def delete_transcript(transcript_selection):
if not transcript_selection:
return "No transcript selected."
transcript_id = int(transcript_selection.split(":")[0])
result = delete_specific_transcript(transcript_id)
return result
def delete_summary(summary_selection):
if not summary_selection:
return "No summary selected."
summary_id = int(summary_selection.split(":")[0])
result = delete_specific_summary(summary_id)
return result
def delete_prompt(prompt_selection):
if not prompt_selection:
return "No prompt selected."
prompt_id = int(prompt_selection.split(":")[0])
result = delete_specific_prompt(prompt_id)
return result
delete_transcript_button.click(
delete_transcript,
inputs=[transcript_selector],
outputs=[status_output]
)
delete_summary_button.click(
delete_summary,
inputs=[summary_selector],
outputs=[status_output]
)
delete_prompt_button.click(
delete_prompt,
inputs=[prompt_selector],
outputs=[status_output]
) |