-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.py
More file actions
96 lines (59 loc) · 2.4 KB
/
Functions.py
File metadata and controls
96 lines (59 loc) · 2.4 KB
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
from Tools import Get_Video_Details,Get_Web_Details,Save_to_chroma,Search_from_chroma
from The_State import State
from LLMs import Extractor,Generator
from colorama import Fore, Back, Style,init
from PIL import Image
import matplotlib.pyplot as plt
import io
import json
init(autoreset=True)
def Save_to_Json(Information):
file_path = "Informations.json"
with open(file_path, "w") as f:
json.dump(Information, f,indent=4)
print(f"Data has been saved to {file_path}")
def Create_RAG(state:State):
print(Style.BRIGHT+Fore.YELLOW+"Create RAG ...")
Youtube_handle = state["Youtube_Handle"]
Documents = Get_Video_Details(Youtube_handle)
Save_to_chroma(Documents)
def Web(state:State):
print(Style.BRIGHT+Fore.YELLOW+"Web Search ...")
Query = state["query"]
Documents = Get_Web_Details(Query)
Save_to_chroma(Documents)
def Get_Context(state:State):
print(Style.BRIGHT+Fore.YELLOW+"Get Context ...")
Query = state.get("query")
return {"Content": Search_from_chroma(Query,5)}
def Extractor_function(state:State):
print(Style.BRIGHT+Fore.GREEN+"Extractor Thinking...")
Context = state["Content"]
Info = state["Response"]
input = {"Content":Context,"Extracted_infos":Info}
Extractor_Response = Extractor.invoke(input)
return {"Response":Extractor_Response.Response}
def Generator_function(state:State):
print(Style.BRIGHT+Fore.GREEN+"Generator Thinking...")
print(Style.BRIGHT+Fore.CYAN+"Iteration :",state["counter"])
input = {"Informations":state["Response"],"Youtube_handle":state["Youtube_Handle"]}
Generator_Response = Generator.invoke(input)
if state["counter"] > 2:
return {"query":Generator_Response.query,"Task_completed":"YES"}
return {"query":Generator_Response.query,"Task_completed":Generator_Response.Done,"counter":state["counter"]+1}
def Condition(state:State):
Save_to_Json(state["Response"])
print(Style.BRIGHT+Fore.CYAN+"Condition ...")
print("State : \n",state["Response"])
Task_completed = state["Task_completed"]
if "YES" in Task_completed.upper():
return "END"
else:
return "CONTINUE"
def Visualize(Graph):
image_data = Graph.get_graph(xray=True).draw_png()
image_buffer = io.BytesIO(image_data)
img = Image.open(image_buffer)
plt.imshow(img)
plt.axis('off') # Hide the axis
plt.show()