Update pages/llm.py
Browse files- pages/llm.py +9 -9
pages/llm.py
CHANGED
@@ -7,8 +7,8 @@ import os
|
|
7 |
from PyPDF2 import PdfReader
|
8 |
from transformers import pipeline
|
9 |
from transformers import AutoModel
|
10 |
-
from googletrans import Translator
|
11 |
-
from transformers import *
|
12 |
|
13 |
|
14 |
###########
|
@@ -22,7 +22,7 @@ from transformers import *
|
|
22 |
|
23 |
# PDF in String umwandeln
|
24 |
def get_pdf_text(folder_path):
|
25 |
-
translator = Translator()
|
26 |
text = ""
|
27 |
# Durchsuche alle Dateien im angegebenen Verzeichnis
|
28 |
for filename in os.listdir(folder_path):
|
@@ -34,9 +34,9 @@ def get_pdf_text(folder_path):
|
|
34 |
for page in pdf_reader.pages:
|
35 |
text += page.extract_text()
|
36 |
#text += '\n'
|
37 |
-
text=text.replace("\n", " ")
|
38 |
-
text=text.replace("- ", "")
|
39 |
-
return translator.translate(text, dest ='en').text
|
40 |
|
41 |
#Chunks erstellen
|
42 |
def get_text_chunks(text):
|
@@ -81,8 +81,8 @@ def get_llm_answer(user_question):
|
|
81 |
#user_question = st.text_area("Stell mir eine Frage: ")
|
82 |
#if os.path.exists("./Store"): #Nutzereingabe nur eingelesen, wenn vectorstore angelegt
|
83 |
# Retriever sucht passende Textausschnitte in den PDFs (unformatiert)
|
84 |
-
translator = Translator()
|
85 |
-
translator.translate(user_question, dest='en')
|
86 |
retriever=get_vectorstore().as_retriever()
|
87 |
retrieved_docs=retriever.invoke(
|
88 |
user_question
|
@@ -99,7 +99,7 @@ def get_llm_answer(user_question):
|
|
99 |
# Frage beantworten mit Q&A Pipeline
|
100 |
answer = qa_pipeline(question=user_question, context=context, max_length=200)
|
101 |
|
102 |
-
return translator.translate(answer["answer"],dest='de')
|
103 |
|
104 |
def main():
|
105 |
st.set_page_config(
|
|
|
7 |
from PyPDF2 import PdfReader
|
8 |
from transformers import pipeline
|
9 |
from transformers import AutoModel
|
10 |
+
#from googletrans import Translator
|
11 |
+
#from transformers import *
|
12 |
|
13 |
|
14 |
###########
|
|
|
22 |
|
23 |
# PDF in String umwandeln
|
24 |
def get_pdf_text(folder_path):
|
25 |
+
#translator = Translator()
|
26 |
text = ""
|
27 |
# Durchsuche alle Dateien im angegebenen Verzeichnis
|
28 |
for filename in os.listdir(folder_path):
|
|
|
34 |
for page in pdf_reader.pages:
|
35 |
text += page.extract_text()
|
36 |
#text += '\n'
|
37 |
+
#text=text.replace("\n", " ")
|
38 |
+
#text=text.replace("- ", "")
|
39 |
+
return text#translator.translate(text, dest ='en').text
|
40 |
|
41 |
#Chunks erstellen
|
42 |
def get_text_chunks(text):
|
|
|
81 |
#user_question = st.text_area("Stell mir eine Frage: ")
|
82 |
#if os.path.exists("./Store"): #Nutzereingabe nur eingelesen, wenn vectorstore angelegt
|
83 |
# Retriever sucht passende Textausschnitte in den PDFs (unformatiert)
|
84 |
+
#translator = Translator()
|
85 |
+
#translator.translate(user_question, dest='en')
|
86 |
retriever=get_vectorstore().as_retriever()
|
87 |
retrieved_docs=retriever.invoke(
|
88 |
user_question
|
|
|
99 |
# Frage beantworten mit Q&A Pipeline
|
100 |
answer = qa_pipeline(question=user_question, context=context, max_length=200)
|
101 |
|
102 |
+
return answer["answer"]#translator.translate(answer["answer"],dest='de')
|
103 |
|
104 |
def main():
|
105 |
st.set_page_config(
|