acecalisto3 commited on
Commit
3000751
·
verified ·
1 Parent(s): 74bd93a

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +16 -23
app2.py CHANGED
@@ -8,7 +8,7 @@ import tempfile
8
  from datetime import datetime
9
  from pathlib import Path
10
  from urllib.parse import urlparse
11
- from typing import List, Dict, Tuple, Union
12
  import requests
13
  import validators
14
  import gradio as gr
@@ -199,29 +199,15 @@ class FileProcessor:
199
 
200
  return dataset
201
 
202
- def _process_zip_file(self, zip_path: str, temp_dir: str) -> List[Dict]:
203
- """Process ZIP file contents"""
204
- results = []
205
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
206
- zip_ref.extractall(temp_dir)
207
- for root, _, files in os.walk(temp_dir):
208
- for filename in files:
209
- filepath = os.path.join(root, filename)
210
- if self.is_text_file(filepath):
211
- try:
212
- with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
213
- content = f.read()
214
- if content.strip():
215
- results.append({
216
- "source": "file",
217
- "filename": filename,
218
- "content": content,
219
- "timestamp": datetime.now().isoformat()
220
- })
221
- except Exception as e:
222
- logger.error(f"Error reading file {filename}: {str(e)}")
223
- return results
224
-
225
  def _process_single_file(self, file) -> List[Dict]:
226
  try:
227
  file_stat = os.stat(file.name)
@@ -260,6 +246,13 @@ def _process_single_file(self, file) -> List[Dict]:
260
 
261
  def generate_qr_code(json_data):
262
  """Generate a QR code from JSON data."""
 
 
 
 
 
 
 
263
  qr = qrcode.make(json_data)
264
  qr_path = "output/qr_code.png"
265
  qr.save(qr_path)
 
8
  from datetime import datetime
9
  from pathlib import Path
10
  from urllib.parse import urlparse
11
+ from typing import List, Dict, Tuple, Union, Optional
12
  import requests
13
  import validators
14
  import gradio as gr
 
199
 
200
  return dataset
201
 
202
+ def process_zip_file(zip_path):
203
+ """Extract and process files within a ZIP archive."""
204
+ extraction_directory = tempfile.mkdtemp()
205
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
206
+ zip_ref.extractall(extraction_directory)
207
+ for extracted_file in os.listdir(extraction_directory):
208
+ extracted_file_path = os.path.join(extraction_directory, extracted_file)
209
+ process_file(extracted_file_path)
210
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  def _process_single_file(self, file) -> List[Dict]:
212
  try:
213
  file_stat = os.stat(file.name)
 
246
 
247
  def generate_qr_code(json_data):
248
  """Generate a QR code from JSON data."""
249
+ # Limit the size of json_data to avoid exceeding QR code version limits
250
+ max_length = 2953 # Maximum length for version 40 (the highest version)
251
+
252
+ if len(json_data) > max_length:
253
+ logger.warning("JSON data is too large for QR code generation. Truncating data.")
254
+ json_data = json_data[:max_length] # Truncate the data
255
+
256
  qr = qrcode.make(json_data)
257
  qr_path = "output/qr_code.png"
258
  qr.save(qr_path)