Update app.py
Browse files
app.py
CHANGED
@@ -65,11 +65,14 @@ YOUTUBE_DIR = "/youtube"
|
|
65 |
|
66 |
###############################################
|
67 |
#URLs zu Dokumenten oder andere Inhalte, die einbezogen werden sollen
|
68 |
-
PDF_URL = "https://arxiv.org/pdf/2303.08774.pdf"
|
69 |
WEB_URL = "https://openai.com/research/gpt-4"
|
70 |
YOUTUBE_URL_1 = "https://www.youtube.com/watch?v=--khbXchTeE"
|
71 |
YOUTUBE_URL_2 = "https://www.youtube.com/watch?v=hdhZwyf24mE"
|
72 |
-
YOUTUBE_URL_3 = "https://www.youtube.com/watch?v=vw-KWfKwvTQ"
|
|
|
|
|
|
|
73 |
|
74 |
|
75 |
################################################
|
@@ -103,28 +106,57 @@ def add_file(history, file):
|
|
103 |
history = history + [((file.name,), None)]
|
104 |
return history
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
#die Inhalte splitten, um in Vektordatenbank entsprechend zu laden als Splits
|
108 |
def document_loading_splitting():
|
109 |
global splittet
|
|
|
|
|
110 |
# Document loading
|
111 |
docs = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
# Load PDF
|
113 |
-
loader = PyPDFLoader(
|
114 |
-
docs.extend(loader.load())
|
115 |
# Load Web
|
116 |
-
loader = WebBaseLoader(WEB_URL)
|
117 |
-
docs.extend(loader.load())
|
118 |
# Load YouTube
|
119 |
-
loader = GenericLoader(YoutubeAudioLoader([YOUTUBE_URL_1,
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
docs.extend(loader.load())
|
124 |
# Document splitting
|
125 |
-
text_splitter = RecursiveCharacterTextSplitter(chunk_overlap = 150,
|
126 |
-
chunk_size = 1500)
|
127 |
splits = text_splitter.split_documents(docs)
|
|
|
128 |
#nur bei erster Anfrage mit "choma" wird gesplittet...
|
129 |
splittet = True
|
130 |
return splits
|
|
|
65 |
|
66 |
###############################################
|
67 |
#URLs zu Dokumenten oder andere Inhalte, die einbezogen werden sollen
|
68 |
+
#PDF_URL = "https://arxiv.org/pdf/2303.08774.pdf"
|
69 |
WEB_URL = "https://openai.com/research/gpt-4"
|
70 |
YOUTUBE_URL_1 = "https://www.youtube.com/watch?v=--khbXchTeE"
|
71 |
YOUTUBE_URL_2 = "https://www.youtube.com/watch?v=hdhZwyf24mE"
|
72 |
+
#YOUTUBE_URL_3 = "https://www.youtube.com/watch?v=vw-KWfKwvTQ"
|
73 |
+
|
74 |
+
#URL zu TIS dokumenten
|
75 |
+
PDF_URL = https://huggingface.co/spaces/alexkueck/LIRAG/blob/main/chroma/1.%20Programmplanung%20in%20LIF15%20_%20MeisterNote.pdf
|
76 |
|
77 |
|
78 |
################################################
|
|
|
106 |
history = history + [((file.name,), None)]
|
107 |
return history
|
108 |
|
109 |
+
# Funktion, um für einen best. File-typ ein directory-loader zu definieren
|
110 |
+
def create_directory_loader(file_type, directory_path):
|
111 |
+
return DirectoryLoader(
|
112 |
+
path=directory_path,
|
113 |
+
glob=f"**/*{file_type}",
|
114 |
+
loader_cls=loaders[file_type],
|
115 |
+
)
|
116 |
|
117 |
#die Inhalte splitten, um in Vektordatenbank entsprechend zu laden als Splits
|
118 |
def document_loading_splitting():
|
119 |
global splittet
|
120 |
+
|
121 |
+
##############################
|
122 |
# Document loading
|
123 |
docs = []
|
124 |
+
#verscheidene Dokument loaders:
|
125 |
+
loaders = {
|
126 |
+
'.pdf': PyMuPDFLoader,
|
127 |
+
'.word': UnstructuredWordDocumentLoader,
|
128 |
+
}
|
129 |
+
|
130 |
+
|
131 |
+
# kreiere einen DirectoryLoader für jeden file type
|
132 |
+
pdf_loader = create_directory_loader('.pdf', './chroma/pdf')
|
133 |
+
word_loader = create_directory_loader('.word', './chroma/word')
|
134 |
+
|
135 |
+
|
136 |
+
# Load the files
|
137 |
+
pdf_documents = pdf_loader.load()
|
138 |
+
word_documents = word_loader.load()
|
139 |
+
|
140 |
+
#alle zusammen in docs...
|
141 |
+
docs.extend(pdf_documents)
|
142 |
+
docs.extend(word_documents)
|
143 |
+
|
144 |
+
#andere loader...
|
145 |
# Load PDF
|
146 |
+
#loader = PyPDFLoader(PDF_URL1)
|
147 |
+
#docs.extend(loader.load())
|
148 |
# Load Web
|
149 |
+
#loader = WebBaseLoader(WEB_URL)
|
150 |
+
#docs.extend(loader.load())
|
151 |
# Load YouTube
|
152 |
+
#loader = GenericLoader(YoutubeAudioLoader([YOUTUBE_URL_1,YOUTUBE_URL_2], PATH_WORK + YOUTUBE_DIR), OpenAIWhisperParser())
|
153 |
+
#docs.extend(loader.load())
|
154 |
+
|
155 |
+
################################
|
|
|
156 |
# Document splitting
|
157 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_overlap = 150, chunk_size = 1500)
|
|
|
158 |
splits = text_splitter.split_documents(docs)
|
159 |
+
|
160 |
#nur bei erster Anfrage mit "choma" wird gesplittet...
|
161 |
splittet = True
|
162 |
return splits
|