Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -92,7 +92,9 @@ def text_extractor(state: State):
|
|
92 |
]
|
93 |
|
94 |
print("I have access to the Open AI API for text extraction.")
|
|
|
95 |
print("I need to format the input image in the Open AI format")
|
|
|
96 |
|
97 |
response = client.chat.completions.create(
|
98 |
model='gpt-4o-mini',
|
@@ -103,6 +105,7 @@ def text_extractor(state: State):
|
|
103 |
extracted_text = response.choices[0].message.content
|
104 |
|
105 |
print("Extracted text from the input image")
|
|
|
106 |
|
107 |
return {'extracted_text': extracted_text}
|
108 |
|
@@ -120,6 +123,7 @@ def categorizer(state: State):
|
|
120 |
"""
|
121 |
|
122 |
print("Categorizing items in the input text to one of: Alcoholic Drinks, Non-Alcoholic Drinks and Food.")
|
|
|
123 |
|
124 |
categorization_prompt = [
|
125 |
SystemMessage(content=categorization_system_message),
|
@@ -134,7 +138,9 @@ def categorizer(state: State):
|
|
134 |
def verifier(state: State):
|
135 |
|
136 |
print("I now have to retrieve relevant sections of the company policy to exclude items that are not reimbursable.")
|
|
|
137 |
print("I will use the search tool to execute this step.")
|
|
|
138 |
|
139 |
for document in company_policy_document:
|
140 |
if document.page_content.find(f'{type_of_expense}') != -1:
|
@@ -164,6 +170,7 @@ def verifier(state: State):
|
|
164 |
def estimator(state: State):
|
165 |
|
166 |
print("Calculating the revised total amount and taxes")
|
|
|
167 |
|
168 |
total_bill = 0
|
169 |
total_taxes_and_charges = 0
|
@@ -183,6 +190,7 @@ def estimator(state: State):
|
|
183 |
|
184 |
def formatter(state: State):
|
185 |
print("Formatting the output into a markdown file")
|
|
|
186 |
|
187 |
final_output_system_message = """
|
188 |
You are an expert accountant tasked to generate the expense claim report.
|
@@ -272,6 +280,8 @@ def claim_generator(input_bill_path, progress=gr.Progress()):
|
|
272 |
output = chain.invoke({'image_path': input_bill_path})
|
273 |
progress(0.25)
|
274 |
|
|
|
|
|
275 |
pdf = MarkdownPdf(toc_level=3)
|
276 |
|
277 |
pdf.add_section(Section(output['final_output']))
|
|
|
92 |
]
|
93 |
|
94 |
print("I have access to the Open AI API for text extraction.")
|
95 |
+
gr.Info("I have access to the Open AI API for text extraction.")
|
96 |
print("I need to format the input image in the Open AI format")
|
97 |
+
gr.Info("I need to format the input image in the Open AI format")
|
98 |
|
99 |
response = client.chat.completions.create(
|
100 |
model='gpt-4o-mini',
|
|
|
105 |
extracted_text = response.choices[0].message.content
|
106 |
|
107 |
print("Extracted text from the input image")
|
108 |
+
gr.Info("Extracted text from the input image")
|
109 |
|
110 |
return {'extracted_text': extracted_text}
|
111 |
|
|
|
123 |
"""
|
124 |
|
125 |
print("Categorizing items in the input text to one of: Alcoholic Drinks, Non-Alcoholic Drinks and Food.")
|
126 |
+
gr.Info("Categorizing items in the input text to one of: Alcoholic Drinks, Non-Alcoholic Drinks and Food.")
|
127 |
|
128 |
categorization_prompt = [
|
129 |
SystemMessage(content=categorization_system_message),
|
|
|
138 |
def verifier(state: State):
|
139 |
|
140 |
print("I now have to retrieve relevant sections of the company policy to exclude items that are not reimbursable.")
|
141 |
+
gr.Info("I now have to retrieve relevant sections of the company policy to exclude items that are not reimbursable.")
|
142 |
print("I will use the search tool to execute this step.")
|
143 |
+
gr.Info("I will use the search tool to execute this step.")
|
144 |
|
145 |
for document in company_policy_document:
|
146 |
if document.page_content.find(f'{type_of_expense}') != -1:
|
|
|
170 |
def estimator(state: State):
|
171 |
|
172 |
print("Calculating the revised total amount and taxes")
|
173 |
+
gr.Info("Calculating the revised total amount and taxes")
|
174 |
|
175 |
total_bill = 0
|
176 |
total_taxes_and_charges = 0
|
|
|
190 |
|
191 |
def formatter(state: State):
|
192 |
print("Formatting the output into a markdown file")
|
193 |
+
gr.Info("Formatting the output into a markdown file")
|
194 |
|
195 |
final_output_system_message = """
|
196 |
You are an expert accountant tasked to generate the expense claim report.
|
|
|
280 |
output = chain.invoke({'image_path': input_bill_path})
|
281 |
progress(0.25)
|
282 |
|
283 |
+
print("Converting the markdown file to pdf")
|
284 |
+
|
285 |
pdf = MarkdownPdf(toc_level=3)
|
286 |
|
287 |
pdf.add_section(Section(output['final_output']))
|