Spaces:
Running
Running
oceansweep
commited on
Commit
•
6f854c9
1
Parent(s):
5fab6ba
Update App_Function_Libraries/RAG/RAG_QA_Chat.py
Browse files
App_Function_Libraries/RAG/RAG_QA_Chat.py
CHANGED
@@ -1,84 +1,52 @@
|
|
1 |
-
# Podcast_tab.py
|
2 |
-
# Description: Gradio UI for ingesting podcasts into the database
|
3 |
-
#
|
4 |
-
# Imports
|
5 |
-
#
|
6 |
-
#
|
7 |
-
# External Imports
|
8 |
-
import json
|
9 |
-
import logging
|
10 |
-
import tempfile
|
11 |
-
from typing import List, Tuple, IO, Union
|
12 |
-
#
|
13 |
-
# Local Imports
|
14 |
-
from App_Function_Libraries.DB.DB_Manager import db, search_db, DatabaseError, get_media_content
|
15 |
-
from App_Function_Libraries.RAG.RAG_Libary_2 import generate_answer
|
16 |
-
#
|
17 |
-
########################################################################################################################
|
18 |
-
#
|
19 |
-
# Functions:
|
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 |
-
def save_chat_history(history: List[Tuple[str, str]]) -> str:
|
57 |
-
# Save chat history to a file
|
58 |
-
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json') as temp_file:
|
59 |
-
json.dump(history, temp_file)
|
60 |
-
return temp_file.name
|
61 |
-
|
62 |
-
|
63 |
-
def load_chat_history(file: IO[str]) -> List[Tuple[str, str]]:
|
64 |
-
# Load chat history from a file
|
65 |
-
return json.load(file)
|
66 |
-
|
67 |
-
|
68 |
-
def search_database(query: str) -> List[Tuple[int, str]]:
|
69 |
-
# Implement database search functionality
|
70 |
-
results = search_db(query, ["title", "content"], "", page=1, results_per_page=10)
|
71 |
-
return [(result['id'], result['title']) for result in results]
|
72 |
-
|
73 |
-
|
74 |
-
def get_existing_files() -> List[Tuple[int, str]]:
|
75 |
-
# Fetch list of existing files from the database
|
76 |
-
with db.get_connection() as conn:
|
77 |
-
cursor = conn.cursor()
|
78 |
-
cursor.execute("SELECT id, title FROM Media ORDER BY title")
|
79 |
-
return cursor.fetchall()
|
80 |
-
|
81 |
-
|
82 |
-
#
|
83 |
-
# End of RAG_QA_Chat.py
|
84 |
-
########################################################################################################################
|
|
|
1 |
+
# Podcast_tab.py
|
2 |
+
# Description: Gradio UI for ingesting podcasts into the database
|
3 |
+
#
|
4 |
+
# Imports
|
5 |
+
#
|
6 |
+
#
|
7 |
+
# External Imports
|
8 |
+
import json
|
9 |
+
import logging
|
10 |
+
import tempfile
|
11 |
+
from typing import List, Tuple, IO, Union
|
12 |
+
#
|
13 |
+
# Local Imports
|
14 |
+
from App_Function_Libraries.DB.DB_Manager import db, search_db, DatabaseError, get_media_content
|
15 |
+
#from App_Function_Libraries.RAG.RAG_Libary_2 import generate_answer
|
16 |
+
#
|
17 |
+
########################################################################################################################
|
18 |
+
#
|
19 |
+
# Functions:
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
def save_chat_history(history: List[Tuple[str, str]]) -> str:
|
25 |
+
# Save chat history to a file
|
26 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json') as temp_file:
|
27 |
+
json.dump(history, temp_file)
|
28 |
+
return temp_file.name
|
29 |
+
|
30 |
+
|
31 |
+
def load_chat_history(file: IO[str]) -> List[Tuple[str, str]]:
|
32 |
+
# Load chat history from a file
|
33 |
+
return json.load(file)
|
34 |
+
|
35 |
+
|
36 |
+
def search_database(query: str) -> List[Tuple[int, str]]:
|
37 |
+
# Implement database search functionality
|
38 |
+
results = search_db(query, ["title", "content"], "", page=1, results_per_page=10)
|
39 |
+
return [(result['id'], result['title']) for result in results]
|
40 |
+
|
41 |
+
|
42 |
+
def get_existing_files() -> List[Tuple[int, str]]:
|
43 |
+
# Fetch list of existing files from the database
|
44 |
+
with db.get_connection() as conn:
|
45 |
+
cursor = conn.cursor()
|
46 |
+
cursor.execute("SELECT id, title FROM Media ORDER BY title")
|
47 |
+
return cursor.fetchall()
|
48 |
+
|
49 |
+
|
50 |
+
#
|
51 |
+
# End of RAG_QA_Chat.py
|
52 |
+
########################################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|