Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,19 +39,6 @@ if not os.path.exists(FAISS_INDEX_DIR):
|
|
| 39 |
# Dictionary to store user-specific vectorstores
|
| 40 |
user_vectorstores = {}
|
| 41 |
|
| 42 |
-
# Load SmolDocling model for image analysis
|
| 43 |
-
def load_docling_model():
|
| 44 |
-
try:
|
| 45 |
-
processor = AutoProcessor.from_pretrained("ds4sd/SmolDocling-256M-preview")
|
| 46 |
-
model = AutoModelForVision2Seq.from_pretrained("ds4sd/SmolDocling-256M-preview")
|
| 47 |
-
return processor, model
|
| 48 |
-
except Exception as e:
|
| 49 |
-
print(f"Error loading SmolDocling model: {e}")
|
| 50 |
-
return None, None
|
| 51 |
-
|
| 52 |
-
# Initialize SmolDocling model
|
| 53 |
-
docling_processor, docling_model = load_docling_model()
|
| 54 |
-
|
| 55 |
# Custom CSS for Tech theme
|
| 56 |
custom_css = """
|
| 57 |
:root {
|
|
@@ -278,39 +265,40 @@ def process_excel(excel_file):
|
|
| 278 |
|
| 279 |
# Function to analyze image using SmolDocling
|
| 280 |
def analyze_image(image_file):
|
|
|
|
|
|
|
|
|
|
| 281 |
if image_file is None:
|
| 282 |
return "No image uploaded. Please upload an image to analyze."
|
| 283 |
|
| 284 |
-
if docling_processor is None or docling_model is None:
|
| 285 |
-
return "SmolDocling model not loaded. Please check your installation."
|
| 286 |
-
|
| 287 |
try:
|
| 288 |
-
# Process the image - image_file is a filepath string from Gradio
|
| 289 |
image = Image.open(image_file)
|
|
|
|
|
|
|
|
|
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
return analysis
|
| 312 |
except Exception as e:
|
| 313 |
-
return f"Error analyzing image: {str(e)}"
|
| 314 |
|
| 315 |
# Function to handle different file types
|
| 316 |
def process_file(file_data, file_type):
|
|
|
|
| 39 |
# Dictionary to store user-specific vectorstores
|
| 40 |
user_vectorstores = {}
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
# Custom CSS for Tech theme
|
| 43 |
custom_css = """
|
| 44 |
:root {
|
|
|
|
| 265 |
|
| 266 |
# Function to analyze image using SmolDocling
|
| 267 |
def analyze_image(image_file):
|
| 268 |
+
"""
|
| 269 |
+
Basic image analysis function that doesn't rely on external models
|
| 270 |
+
"""
|
| 271 |
if image_file is None:
|
| 272 |
return "No image uploaded. Please upload an image to analyze."
|
| 273 |
|
|
|
|
|
|
|
|
|
|
| 274 |
try:
|
|
|
|
| 275 |
image = Image.open(image_file)
|
| 276 |
+
width, height = image.size
|
| 277 |
+
format = image.format
|
| 278 |
+
mode = image.mode
|
| 279 |
|
| 280 |
+
analysis = f"""## Technical Document Analysis
|
| 281 |
+
|
| 282 |
+
**Image Properties:**
|
| 283 |
+
- Dimensions: {width}x{height} pixels
|
| 284 |
+
- Format: {format}
|
| 285 |
+
- Color Mode: {mode}
|
| 286 |
+
|
| 287 |
+
**Technical Analysis:**
|
| 288 |
+
1. Document Quality:
|
| 289 |
+
- Resolution: {'High' if width > 2000 or height > 2000 else 'Medium' if width > 1000 or height > 1000 else 'Low'}
|
| 290 |
+
- Color Depth: {mode}
|
| 291 |
+
|
| 292 |
+
2. Recommendations:
|
| 293 |
+
- For text extraction, consider using PDF format
|
| 294 |
+
- For technical diagrams, ensure high resolution
|
| 295 |
+
- Consider OCR for text content
|
| 296 |
+
|
| 297 |
+
**Note:** For detailed technical analysis, please convert to PDF format
|
| 298 |
+
"""
|
|
|
|
| 299 |
return analysis
|
| 300 |
except Exception as e:
|
| 301 |
+
return f"Error analyzing image: {str(e)}\n\nPlease try using PDF format instead."
|
| 302 |
|
| 303 |
# Function to handle different file types
|
| 304 |
def process_file(file_data, file_type):
|