Update backend.py
Browse files- backend.py +10 -1
backend.py
CHANGED
|
@@ -60,7 +60,16 @@ class InvoicePipeline:
|
|
| 60 |
def _extract_data_from_llm(self, raw_data:str) -> str:
|
| 61 |
resp = self._llm(self._prompt_template.format(pages = raw_data))
|
| 62 |
return resp
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
|
|
|
|
| 60 |
def _extract_data_from_llm(self, raw_data:str) -> str:
|
| 61 |
resp = self._llm(self._prompt_template.format(pages = raw_data))
|
| 62 |
return resp
|
| 63 |
+
|
| 64 |
+
def _parse_response(self, response: str) -> Dict[str, str]:
|
| 65 |
+
pattern = r'{(.+)}'
|
| 66 |
+
re_match = re.search(pattern, response, re.DOTALL)
|
| 67 |
+
if re_match:
|
| 68 |
+
extracted_text = re_match.group(1)
|
| 69 |
+
data = eval('{' + extracted_text + '}')
|
| 70 |
+
return data
|
| 71 |
+
else:
|
| 72 |
+
raise Exception("No match found.")
|
| 73 |
|
| 74 |
|
| 75 |
|