Spaces:
Running
Running
Update app.py
Browse files
app.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,15 +199,29 @@ class FileProcessor:
|
|
199 |
|
200 |
return dataset
|
201 |
|
202 |
-
def
|
203 |
-
"""
|
204 |
-
|
205 |
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
206 |
-
zip_ref.extractall(
|
207 |
-
for
|
208 |
-
|
209 |
-
|
210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
def _process_single_file(self, file) -> List[Dict]:
|
212 |
try:
|
213 |
file_stat = os.stat(file.name)
|
@@ -246,13 +260,6 @@ def _process_single_file(self, file) -> List[Dict]:
|
|
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)
|
|
|
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 |
|
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 |
|
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)
|