Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -342,11 +342,14 @@ class EnhancedFileProcessor:
|
|
342 |
logger.error(f"Archive processing error: {e}")
|
343 |
return dataset
|
344 |
|
345 |
-
def chunk_data(self, data: Union[Dict, List], max_size: int = 2953) -> List[Dict]:
|
346 |
"""Enhanced data chunking with sequence metadata"""
|
347 |
try:
|
348 |
-
|
349 |
-
|
|
|
|
|
|
|
350 |
total_length = len(json_str)
|
351 |
|
352 |
# Calculate overhead for metadata
|
@@ -407,7 +410,7 @@ def generate_stylish_qr(data: Union[str, Dict],
|
|
407 |
try:
|
408 |
qr = qrcode.QRCode(
|
409 |
version=None,
|
410 |
-
error_correction=qrcode.constants.
|
411 |
box_size=size,
|
412 |
border=border
|
413 |
)
|
@@ -457,7 +460,7 @@ def generate_qr_codes(data: Union[str, Dict, List], combined: bool = True) -> Li
|
|
457 |
for i, chunk in enumerate(chunks):
|
458 |
filename = f'combined_qr_{int(time.time())}_{i+1}_of_{len(chunks)}.png'
|
459 |
qr_path = generate_stylish_qr(
|
460 |
-
data=chunk,
|
461 |
filename=filename,
|
462 |
fill_color="#1a365d", # Deep blue
|
463 |
back_color="#ffffff"
|
@@ -472,7 +475,7 @@ def generate_qr_codes(data: Union[str, Dict, List], combined: bool = True) -> Li
|
|
472 |
for chunk_idx, chunk in enumerate(chunks):
|
473 |
filename = f'item_{idx+1}_chunk_{chunk_idx+1}_of_{len(chunks)}_{int(time.time())}.png'
|
474 |
qr_path = generate_stylish_qr(
|
475 |
-
data=chunk,
|
476 |
filename=filename,
|
477 |
fill_color="#1a365d", # Deep blue
|
478 |
back_color="#ffffff"
|
@@ -484,7 +487,7 @@ def generate_qr_codes(data: Union[str, Dict, List], combined: bool = True) -> Li
|
|
484 |
for i, chunk in enumerate(chunks):
|
485 |
filename = f'single_qr_{i+1}_of_{len(chunks)}_{int(time.time())}.png'
|
486 |
qr_path = generate_stylish_qr(
|
487 |
-
data=chunk,
|
488 |
filename=filename,
|
489 |
fill_color="#1a365d", # Deep blue
|
490 |
back_color="#ffffff"
|
@@ -804,14 +807,19 @@ def create_modern_interface():
|
|
804 |
for url in url_list:
|
805 |
validation = url_processor.validate_url(url)
|
806 |
if validation['is_valid']:
|
807 |
-
|
808 |
-
if content:
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
|
|
|
|
|
|
|
|
|
|
815 |
|
816 |
# Process files
|
817 |
if files:
|
|
|
342 |
logger.error(f"Archive processing error: {e}")
|
343 |
return dataset
|
344 |
|
345 |
+
def chunk_data(self, data: Union[Dict, List, str], max_size: int = 2953) -> List[Dict]:
|
346 |
"""Enhanced data chunking with sequence metadata"""
|
347 |
try:
|
348 |
+
if not isinstance(data, str):
|
349 |
+
# Convert data to JSON string
|
350 |
+
json_str = json.dumps(data, ensure_ascii=False)
|
351 |
+
else:
|
352 |
+
json_str = data
|
353 |
total_length = len(json_str)
|
354 |
|
355 |
# Calculate overhead for metadata
|
|
|
410 |
try:
|
411 |
qr = qrcode.QRCode(
|
412 |
version=None,
|
413 |
+
error_correction=qrcode.constants.ERROR_CORRECT_H,
|
414 |
box_size=size,
|
415 |
border=border
|
416 |
)
|
|
|
460 |
for i, chunk in enumerate(chunks):
|
461 |
filename = f'combined_qr_{int(time.time())}_{i+1}_of_{len(chunks)}.png'
|
462 |
qr_path = generate_stylish_qr(
|
463 |
+
data=chunk['data'], # Use the 'data' part of the chunk
|
464 |
filename=filename,
|
465 |
fill_color="#1a365d", # Deep blue
|
466 |
back_color="#ffffff"
|
|
|
475 |
for chunk_idx, chunk in enumerate(chunks):
|
476 |
filename = f'item_{idx+1}_chunk_{chunk_idx+1}_of_{len(chunks)}_{int(time.time())}.png'
|
477 |
qr_path = generate_stylish_qr(
|
478 |
+
data=chunk['data'], # Use the 'data' part of the chunk
|
479 |
filename=filename,
|
480 |
fill_color="#1a365d", # Deep blue
|
481 |
back_color="#ffffff"
|
|
|
487 |
for i, chunk in enumerate(chunks):
|
488 |
filename = f'single_qr_{i+1}_of_{len(chunks)}_{int(time.time())}.png'
|
489 |
qr_path = generate_stylish_qr(
|
490 |
+
data=chunk['data'], # Use the 'data' part of the chunk
|
491 |
filename=filename,
|
492 |
fill_color="#1a365d", # Deep blue
|
493 |
back_color="#ffffff"
|
|
|
807 |
for url in url_list:
|
808 |
validation = url_processor.validate_url(url)
|
809 |
if validation['is_valid']:
|
810 |
+
content_data = url_processor.fetch_content(url)
|
811 |
+
if content_data and 'content' in content_data:
|
812 |
+
# Chunk the content of each URL
|
813 |
+
chunks = file_processor.chunk_data(content_data['content'])
|
814 |
+
for i, chunk in enumerate(chunks):
|
815 |
+
results.append({
|
816 |
+
'source': 'url',
|
817 |
+
'url': url,
|
818 |
+
'chunk_index': i + 1,
|
819 |
+
'total_chunks': len(chunks),
|
820 |
+
'content': chunk['data'], # Store the chunked data
|
821 |
+
'timestamp': datetime.now().isoformat()
|
822 |
+
})
|
823 |
|
824 |
# Process files
|
825 |
if files:
|