Update backend.py
Browse files- backend.py +5 -7
backend.py
CHANGED
@@ -7,7 +7,7 @@ from langchain.prompts import PromptTemplate
|
|
7 |
from langchain_google_genai import GoogleGenerativeAI
|
8 |
|
9 |
|
10 |
-
|
11 |
|
12 |
|
13 |
class InvoicePipeline:
|
@@ -19,14 +19,14 @@ class InvoicePipeline:
|
|
19 |
# This funcition will help in extracting and run the code, and will produce a dataframe for us
|
20 |
def run(self) -> pd.DataFrame:
|
21 |
# We have defined the way the data has to be returned
|
22 |
-
df = pd.DataFrame(
|
23 |
"Invoice ID": pd.Series(dtype = "int"),
|
24 |
"DESCRIPTION": pd.Series(dtype = "str"),
|
25 |
"Issue Data": pd.Series(dtype = "str"),
|
26 |
"UNIT PRICE": pd.Series(dtype = "str"),
|
27 |
"AMOUNT": pd.Series(dtype = "int"),
|
28 |
"Bill For": pd.Series(dtype = "str"),
|
29 |
-
"From": pd.Series(dtype ="
|
30 |
"Terms": pd.Series(dtype = "str")}
|
31 |
)
|
32 |
|
@@ -41,7 +41,7 @@ class InvoicePipeline:
|
|
41 |
# The default template that the machine will take
|
42 |
def _get_default_prompt_template(self) -> PromptTemplate:
|
43 |
template = """Extract all the following values: Invoice ID, DESCRIPTION, Issue Data,UNIT PRICE, AMOUNT, Bill for, From and Terms for: {pages}
|
44 |
-
Expected Outcome: remove any dollar symbols {{"Invoice ID":"12341234", "DESCRIPTION": "UNIT PRICE", "AMOUNT": "3", "Date": "2/1/2021", "AMOUNT": "100", "Bill For": "
|
45 |
"""
|
46 |
|
47 |
prompt_template = PromptTemplate(input_variables = ["pages"], template = template)
|
@@ -58,6 +58,4 @@ class InvoicePipeline:
|
|
58 |
|
59 |
def _extract_data_from_llm(self, raw_data:str) -> str:
|
60 |
resp = self._llm(self._prompt_template.format(pages = raw_data))
|
61 |
-
return resp
|
62 |
-
|
63 |
-
|
|
|
7 |
from langchain_google_genai import GoogleGenerativeAI
|
8 |
|
9 |
|
10 |
+
api_key = "AIzaSyCYGj5e2eAQbUi9HtuMaW0LDSnDuxLG54U"
|
11 |
|
12 |
|
13 |
class InvoicePipeline:
|
|
|
19 |
# This funcition will help in extracting and run the code, and will produce a dataframe for us
|
20 |
def run(self) -> pd.DataFrame:
|
21 |
# We have defined the way the data has to be returned
|
22 |
+
df = pd.DataFrame({
|
23 |
"Invoice ID": pd.Series(dtype = "int"),
|
24 |
"DESCRIPTION": pd.Series(dtype = "str"),
|
25 |
"Issue Data": pd.Series(dtype = "str"),
|
26 |
"UNIT PRICE": pd.Series(dtype = "str"),
|
27 |
"AMOUNT": pd.Series(dtype = "int"),
|
28 |
"Bill For": pd.Series(dtype = "str"),
|
29 |
+
"From": pd.Series(dtype ="str"),
|
30 |
"Terms": pd.Series(dtype = "str")}
|
31 |
)
|
32 |
|
|
|
41 |
# The default template that the machine will take
|
42 |
def _get_default_prompt_template(self) -> PromptTemplate:
|
43 |
template = """Extract all the following values: Invoice ID, DESCRIPTION, Issue Data,UNIT PRICE, AMOUNT, Bill for, From and Terms for: {pages}
|
44 |
+
Expected Outcome: remove any dollar symbols {{"Invoice ID":"12341234", "DESCRIPTION": "UNIT PRICE", "AMOUNT": "3", "Date": "2/1/2021", "AMOUNT": "100", "Bill For": "Dev", "From": "Coca Cola", "Terms" : "Net for 30 days"}}
|
45 |
"""
|
46 |
|
47 |
prompt_template = PromptTemplate(input_variables = ["pages"], template = template)
|
|
|
58 |
|
59 |
def _extract_data_from_llm(self, raw_data:str) -> str:
|
60 |
resp = self._llm(self._prompt_template.format(pages = raw_data))
|
61 |
+
return resp
|
|
|
|