Bhaskar2611 commited on
Commit
52ebfdc
·
verified ·
1 Parent(s): df86a91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -8,17 +8,17 @@ import pandas as pd
8
  import torch
9
 
10
  # Load Hugging Face token from environment
11
- hf_token = os.getenv("HF_TOKEN") # Set this in Space Secrets [[2]]
12
 
13
- # Load Mistral-7B-Instruct with authentication
14
  model_name = "mistralai/Mistral-7B-Instruct-v0.3"
15
 
16
  try:
17
- tokenizer = AutoTokenizer.from_pretrained(model_name, token=hf_token)
18
  model = AutoModelForCausalLM.from_pretrained(
19
  model_name,
20
  torch_dtype=torch.float16,
21
- token=hf_token # Pass token for gated repo access [[6]]
22
  )
23
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=500)
24
  except Exception as e:
@@ -47,8 +47,10 @@ def parse_bank_statement(text):
47
  - Debit / Credit
48
  - Closing Balance
49
  - Expense Type (if available)
 
50
  Return the results in JSON format with keys:
51
  ["date", "description", "amount", "debit_credit", "closing_balance", "expense_type"].
 
52
  Example:
53
  {{
54
  "transactions": [
@@ -62,6 +64,7 @@ def parse_bank_statement(text):
62
  }}
63
  ]
64
  }}
 
65
  Bank Statement Text:
66
  {text}
67
  """
 
8
  import torch
9
 
10
  # Load Hugging Face token from environment
11
+ hf_token = os.getenv("HF_TOKEN") # Set this in Space Secrets
12
 
13
+ # Load Mistral-7B-Instruct with authentication and fast tokenizer
14
  model_name = "mistralai/Mistral-7B-Instruct-v0.3"
15
 
16
  try:
17
+ tokenizer = AutoTokenizer.from_pretrained(model_name, token=hf_token, use_fast=True)
18
  model = AutoModelForCausalLM.from_pretrained(
19
  model_name,
20
  torch_dtype=torch.float16,
21
+ token=hf_token
22
  )
23
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_new_tokens=500)
24
  except Exception as e:
 
47
  - Debit / Credit
48
  - Closing Balance
49
  - Expense Type (if available)
50
+
51
  Return the results in JSON format with keys:
52
  ["date", "description", "amount", "debit_credit", "closing_balance", "expense_type"].
53
+
54
  Example:
55
  {{
56
  "transactions": [
 
64
  }}
65
  ]
66
  }}
67
+
68
  Bank Statement Text:
69
  {text}
70
  """