Update app.py
Browse files
app.py
CHANGED
|
@@ -13,18 +13,27 @@ def read_pdf(pdf_path):
|
|
| 13 |
|
| 14 |
# Process and retrieve answers
|
| 15 |
def process_invoice(file, hf_token, questions):
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Gradio interface
|
| 30 |
def gradio_interface(file, hf_token, questions):
|
|
|
|
| 13 |
|
| 14 |
# Process and retrieve answers
|
| 15 |
def process_invoice(file, hf_token, questions):
|
| 16 |
+
try:
|
| 17 |
+
# Read the PDF content directly
|
| 18 |
+
print("Reading PDF content...")
|
| 19 |
+
pdf_content = read_pdf(file.name)
|
| 20 |
+
print(f"PDF Content: {pdf_content[:500]}...") # Print first 500 characters for verification
|
| 21 |
+
|
| 22 |
+
# Initialize the Hugging Face pipeline
|
| 23 |
+
print("Initializing the Hugging Face pipeline...")
|
| 24 |
+
qa_pipeline = pipeline("question-answering", model="mistralai/Mixtral-8x7B-Instruct-v0.1", use_auth_token=hf_token)
|
| 25 |
+
|
| 26 |
+
answers = {}
|
| 27 |
+
for question in questions.split(','):
|
| 28 |
+
print(f"Asking question: {question.strip()}")
|
| 29 |
+
result = qa_pipeline(question=question.strip(), context=pdf_content)
|
| 30 |
+
answers[question] = result['answer']
|
| 31 |
+
print(f"Answer: {result['answer']}")
|
| 32 |
+
|
| 33 |
+
return answers
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Error: {e}")
|
| 36 |
+
return {"error": str(e)}
|
| 37 |
|
| 38 |
# Gradio interface
|
| 39 |
def gradio_interface(file, hf_token, questions):
|