muradkhan commited on
Commit
954da24
1 Parent(s): bf9d3cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
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
- # Read the PDF content directly
17
- pdf_content = read_pdf(file.name)
18
-
19
- # Initialize the Hugging Face pipeline
20
- qa_pipeline = pipeline("question-answering", model="mistralai/Mixtral-8x7B-Instruct-v0.1", token=hf_token)
21
-
22
- answers = {}
23
- for question in questions.split(','):
24
- result = qa_pipeline(question=question.strip(), context=pdf_content)
25
- answers[question] = result['answer']
26
-
27
- return answers
 
 
 
 
 
 
 
 
 
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):