Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
from langchain_community.document_loaders import PyPDFLoader
|
4 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
5 |
from transformers import LayoutLMv3Processor, AutoModelForTokenClassification
|
@@ -41,25 +41,23 @@ def process_pdf_and_query(pdf_path, question):
|
|
41 |
return response
|
42 |
|
43 |
def chatbot_response(pdf, question):
|
44 |
-
#
|
45 |
-
pdf_path = "uploaded_pdf.pdf"
|
46 |
-
|
47 |
-
# 'pdf' ist ein NamedString-Objekt. Wir müssen den Inhalt extrahieren und speichern
|
48 |
with open(pdf_path, "wb") as f:
|
49 |
-
f.write(pdf.read()) #
|
50 |
-
|
51 |
-
# OCR-
|
52 |
extracted_text = ocr_tool.extract_text(pdf_path)
|
53 |
|
54 |
-
#
|
55 |
answer = process_pdf_and_query(pdf_path, question)
|
56 |
|
57 |
-
#
|
58 |
os.remove(pdf_path)
|
59 |
-
|
60 |
return answer
|
61 |
|
62 |
-
#
|
63 |
pdf_input = gr.File(label="PDF-Datei hochladen")
|
64 |
question_input = gr.Textbox(label="Frage eingeben")
|
65 |
response_output = gr.Textbox(label="Antwort")
|
@@ -73,4 +71,4 @@ interface = gr.Interface(
|
|
73 |
)
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
-
interface.launch(
|
|
|
1 |
import gradio as gr
|
2 |
+
from langchain.vectorstores import Chroma
|
3 |
from langchain_community.document_loaders import PyPDFLoader
|
4 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
5 |
from transformers import LayoutLMv3Processor, AutoModelForTokenClassification
|
|
|
41 |
return response
|
42 |
|
43 |
def chatbot_response(pdf, question):
|
44 |
+
# Wir speichern die hochgeladene PDF-Datei als temporäre Datei
|
45 |
+
pdf_path = "/tmp/uploaded_pdf.pdf"
|
|
|
|
|
46 |
with open(pdf_path, "wb") as f:
|
47 |
+
f.write(pdf.read()) # PDF-Inhalt als Byte-Stream speichern
|
48 |
+
|
49 |
+
# OCR-Text extrahieren
|
50 |
extracted_text = ocr_tool.extract_text(pdf_path)
|
51 |
|
52 |
+
# Frage beantworten basierend auf der PDF und OCR-Inhalten
|
53 |
answer = process_pdf_and_query(pdf_path, question)
|
54 |
|
55 |
+
# Temporäre Datei löschen
|
56 |
os.remove(pdf_path)
|
57 |
+
|
58 |
return answer
|
59 |
|
60 |
+
# Ändere 'inputs' und 'outputs' zur neuen Gradio API
|
61 |
pdf_input = gr.File(label="PDF-Datei hochladen")
|
62 |
question_input = gr.Textbox(label="Frage eingeben")
|
63 |
response_output = gr.Textbox(label="Antwort")
|
|
|
71 |
)
|
72 |
|
73 |
if __name__ == "__main__":
|
74 |
+
interface.launch()
|