Spaces:
Build error
Build error
iamrobotbear
commited on
Commit
•
53dde32
1
Parent(s):
cf785f9
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ import logging
|
|
14 |
import os
|
15 |
|
16 |
# Configure logging
|
17 |
-
logging.basicConfig(level=logging.
|
18 |
|
19 |
# Load model and preprocessors for Image-Text Matching (LAVIS)
|
20 |
device = torch.device("cuda") if torch.cuda.is_available() else "cpu"
|
@@ -81,8 +81,14 @@ def is_image_file(file):
|
|
81 |
return file_extension.lower() in allowed_extensions
|
82 |
|
83 |
|
|
|
84 |
# Main function to perform image captioning and image-text matching
|
85 |
def process_images_and_statements(file):
|
|
|
|
|
|
|
|
|
|
|
86 |
# Check if the uploaded file is an image
|
87 |
if not is_image_file(file):
|
88 |
return "Invalid file type. Please upload an image file (e.g., .jpg, .png, .jpeg)."
|
@@ -91,7 +97,13 @@ def process_images_and_statements(file):
|
|
91 |
filename = file.name
|
92 |
|
93 |
# Load the image data from the file (convert file object to bytes using file.read())
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
# Generate image caption for the uploaded image using git-large-r-textcaps
|
97 |
caption = generate_caption(git_processor_large_textcaps, git_model_large_textcaps, image)
|
|
|
14 |
import os
|
15 |
|
16 |
# Configure logging
|
17 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
18 |
|
19 |
# Load model and preprocessors for Image-Text Matching (LAVIS)
|
20 |
device = torch.device("cuda") if torch.cuda.is_available() else "cpu"
|
|
|
81 |
return file_extension.lower() in allowed_extensions
|
82 |
|
83 |
|
84 |
+
# Main function to perform image captioning and image-text matching
|
85 |
# Main function to perform image captioning and image-text matching
|
86 |
def process_images_and_statements(file):
|
87 |
+
logging.debug("Entered process_images_and_statements function")
|
88 |
+
logging.debug(f"File object: {file}")
|
89 |
+
logging.debug(f"File name: {file.name}")
|
90 |
+
logging.debug(f"File size: {file.tell()}")
|
91 |
+
|
92 |
# Check if the uploaded file is an image
|
93 |
if not is_image_file(file):
|
94 |
return "Invalid file type. Please upload an image file (e.g., .jpg, .png, .jpeg)."
|
|
|
97 |
filename = file.name
|
98 |
|
99 |
# Load the image data from the file (convert file object to bytes using file.read())
|
100 |
+
try:
|
101 |
+
logging.debug("Attempting to open image")
|
102 |
+
image = Image.open(io.BytesIO(file.read()))
|
103 |
+
logging.debug("Image opened successfully")
|
104 |
+
except Exception as e:
|
105 |
+
logging.exception("Error occurred while opening image")
|
106 |
+
return str(e) # Return error message to the user
|
107 |
|
108 |
# Generate image caption for the uploaded image using git-large-r-textcaps
|
109 |
caption = generate_caption(git_processor_large_textcaps, git_model_large_textcaps, image)
|