Spaces:
Paused
Paused
one more
Browse files
app.py
CHANGED
|
@@ -98,26 +98,36 @@ def demo(image_path, prompt):
|
|
| 98 |
return json
|
| 99 |
|
| 100 |
def process_document(image):
|
|
|
|
|
|
|
|
|
|
| 101 |
# Save the uploaded image to a temporary file
|
| 102 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp_file:
|
| 103 |
image = Image.fromarray(image) # Convert NumPy array to PIL Image
|
| 104 |
image.save(tmp_file.name) # Save the image to the temporary file
|
| 105 |
image_path = tmp_file.name # Get the path of the saved file
|
| 106 |
-
|
|
|
|
|
|
|
| 107 |
# Process the image with your model
|
| 108 |
one = demo(image_path, other_benifits)
|
| 109 |
-
logging.info("
|
|
|
|
| 110 |
two = demo(image_path, tax_deductions)
|
|
|
|
|
|
|
| 111 |
json_op = {
|
| 112 |
"tax_deductions": one,
|
| 113 |
"other_benifits": two
|
| 114 |
}
|
| 115 |
|
| 116 |
-
# Optionally,
|
| 117 |
os.remove(image_path)
|
|
|
|
| 118 |
|
| 119 |
return json_op
|
| 120 |
|
|
|
|
| 121 |
# Create Gradio interface
|
| 122 |
demo = gr.Interface(
|
| 123 |
fn=process_document,
|
|
|
|
| 98 |
return json
|
| 99 |
|
| 100 |
def process_document(image):
|
| 101 |
+
# Log the function start
|
| 102 |
+
logging.info("Started processing the document")
|
| 103 |
+
|
| 104 |
# Save the uploaded image to a temporary file
|
| 105 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp_file:
|
| 106 |
image = Image.fromarray(image) # Convert NumPy array to PIL Image
|
| 107 |
image.save(tmp_file.name) # Save the image to the temporary file
|
| 108 |
image_path = tmp_file.name # Get the path of the saved file
|
| 109 |
+
|
| 110 |
+
logging.info("The path made for image: %s", image_path)
|
| 111 |
+
|
| 112 |
# Process the image with your model
|
| 113 |
one = demo(image_path, other_benifits)
|
| 114 |
+
logging.info("Processed the image for other benefits")
|
| 115 |
+
|
| 116 |
two = demo(image_path, tax_deductions)
|
| 117 |
+
logging.info("Processed the image for tax deductions")
|
| 118 |
+
|
| 119 |
json_op = {
|
| 120 |
"tax_deductions": one,
|
| 121 |
"other_benifits": two
|
| 122 |
}
|
| 123 |
|
| 124 |
+
# Optionally, delete the temporary file after use
|
| 125 |
os.remove(image_path)
|
| 126 |
+
logging.info("Temporary file deleted: %s", image_path)
|
| 127 |
|
| 128 |
return json_op
|
| 129 |
|
| 130 |
+
|
| 131 |
# Create Gradio interface
|
| 132 |
demo = gr.Interface(
|
| 133 |
fn=process_document,
|