Mahdi Naser Moghadasi commited on
Commit
a41632c
ยท
1 Parent(s): 6f840ea

Fix image pattern matching and add debug logging

Browse files

- Added support for markdown bold format: **[๐Ÿ“ธ Image: ...]**
- Added comprehensive regex patterns for all image formats
- Added debug logging to track pattern matching
- Enhanced pattern matching for better content processing
- Added content preview logging for debugging

Files changed (1) hide show
  1. utils.py +8 -2
utils.py CHANGED
@@ -146,6 +146,10 @@ def process_content_with_images(content, topic, content_type):
146
  """Process generated content to include real images and multimedia elements"""
147
  from ai_services import get_educational_image_url, generate_image_placeholder
148
 
 
 
 
 
149
  # Replace image placeholders with actual images
150
  # Convert LaTeX-style math expressions to HTML first
151
  content = convert_math_to_html(content)
@@ -212,16 +216,18 @@ def process_content_with_images(content, topic, content_type):
212
  image_patterns = [
213
  re.compile(r'\[IMAGE:\s*([^\]]+)\]', re.IGNORECASE),
214
  re.compile(r'IMAGE:\s*([^\n]+)', re.IGNORECASE),
 
215
  re.compile(r'\[๐Ÿ“ธ\s*Image:\s*([^\]]+)\]', re.IGNORECASE),
216
  re.compile(r'๐Ÿ“ธ\s*Image:\s*([^\n]+)', re.IGNORECASE),
 
217
  re.compile(r'\[๐Ÿ“ธ\s*Image:\s*([^\]]+)\]\s*Visual content would appear here', re.IGNORECASE),
218
  re.compile(r'๐Ÿ“ธ\s*Image:\s*([^\n]+)\s*Visual content would appear here', re.IGNORECASE)
219
  ]
220
 
221
- for pattern in image_patterns:
222
  def replace_image(match):
223
  description = match.group(1).strip()
224
- print(f"๐Ÿ–ผ๏ธ Processing image: {description}")
225
 
226
  # Try to get a real image URL
227
  image_url = get_educational_image_url(topic, description, content_type)
 
146
  """Process generated content to include real images and multimedia elements"""
147
  from ai_services import get_educational_image_url, generate_image_placeholder
148
 
149
+ print(f"๐Ÿ–ผ๏ธ Processing content for topic: {topic}, type: {content_type}")
150
+ print(f"๐Ÿ–ผ๏ธ Content length: {len(content)} characters")
151
+ print(f"๐Ÿ–ผ๏ธ First 500 chars: {content[:500]}")
152
+
153
  # Replace image placeholders with actual images
154
  # Convert LaTeX-style math expressions to HTML first
155
  content = convert_math_to_html(content)
 
216
  image_patterns = [
217
  re.compile(r'\[IMAGE:\s*([^\]]+)\]', re.IGNORECASE),
218
  re.compile(r'IMAGE:\s*([^\n]+)', re.IGNORECASE),
219
+ re.compile(r'\*\*\[๐Ÿ“ธ\s*Image:\s*([^\]]+)\]\*\*', re.IGNORECASE),
220
  re.compile(r'\[๐Ÿ“ธ\s*Image:\s*([^\]]+)\]', re.IGNORECASE),
221
  re.compile(r'๐Ÿ“ธ\s*Image:\s*([^\n]+)', re.IGNORECASE),
222
+ re.compile(r'\*\*\[๐Ÿ“ธ\s*Image:\s*([^\]]+)\]\*\*\s*\*Visual content would appear here\*', re.IGNORECASE),
223
  re.compile(r'\[๐Ÿ“ธ\s*Image:\s*([^\]]+)\]\s*Visual content would appear here', re.IGNORECASE),
224
  re.compile(r'๐Ÿ“ธ\s*Image:\s*([^\n]+)\s*Visual content would appear here', re.IGNORECASE)
225
  ]
226
 
227
+ for i, pattern in enumerate(image_patterns):
228
  def replace_image(match):
229
  description = match.group(1).strip()
230
+ print(f"๐Ÿ–ผ๏ธ Processing image with pattern {i+1}: {description}")
231
 
232
  # Try to get a real image URL
233
  image_url = get_educational_image_url(topic, description, content_type)