Spaces:
Running
Running
File size: 1,597 Bytes
6f854c9 |
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 |
# Podcast_tab.py
# Description: Gradio UI for ingesting podcasts into the database
#
# Imports
#
#
# External Imports
import json
import logging
import tempfile
from typing import List, Tuple, IO, Union
#
# Local Imports
from App_Function_Libraries.DB.DB_Manager import db, search_db, DatabaseError, get_media_content
#from App_Function_Libraries.RAG.RAG_Libary_2 import generate_answer
#
########################################################################################################################
#
# Functions:
def save_chat_history(history: List[Tuple[str, str]]) -> str:
# Save chat history to a file
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json') as temp_file:
json.dump(history, temp_file)
return temp_file.name
def load_chat_history(file: IO[str]) -> List[Tuple[str, str]]:
# Load chat history from a file
return json.load(file)
def search_database(query: str) -> List[Tuple[int, str]]:
# Implement database search functionality
results = search_db(query, ["title", "content"], "", page=1, results_per_page=10)
return [(result['id'], result['title']) for result in results]
def get_existing_files() -> List[Tuple[int, str]]:
# Fetch list of existing files from the database
with db.get_connection() as conn:
cursor = conn.cursor()
cursor.execute("SELECT id, title FROM Media ORDER BY title")
return cursor.fetchall()
#
# End of RAG_QA_Chat.py
########################################################################################################################
|