Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -284,6 +284,67 @@ class FileProcessor:
|
|
284 |
img.save(temp_file.name)
|
285 |
return temp_file.name
|
286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
def create_interface():
|
288 |
"""Create a comprehensive Gradio interface with advanced features"""
|
289 |
css = """
|
|
|
284 |
img.save(temp_file.name)
|
285 |
return temp_file.name
|
286 |
|
287 |
+
def process_all_inputs(urls, file, text, notes):
|
288 |
+
"""Process all input types with progress tracking"""
|
289 |
+
try:
|
290 |
+
processor = URLProcessor()
|
291 |
+
file_processor = FileProcessor()
|
292 |
+
results = []
|
293 |
+
|
294 |
+
# Process URLs
|
295 |
+
if urls:
|
296 |
+
url_list = re.split(r'[,\n]', urls)
|
297 |
+
url_list = [url.strip() for url in url_list if url.strip()]
|
298 |
+
|
299 |
+
for url in url_list:
|
300 |
+
validation = processor.validate_url(url)
|
301 |
+
if validation.get('is_valid'):
|
302 |
+
content = processor.fetch_content(url)
|
303 |
+
if content:
|
304 |
+
results.append({
|
305 |
+
'source': 'url',
|
306 |
+
'url': url,
|
307 |
+
'content': content,
|
308 |
+
'timestamp': datetime.now().isoformat()
|
309 |
+
})
|
310 |
+
|
311 |
+
# Process files
|
312 |
+
if file:
|
313 |
+
results.extend(file_processor.process_file(file))
|
314 |
+
|
315 |
+
# Process text input
|
316 |
+
if text:
|
317 |
+
cleaned_text = processor.advanced_text_cleaning(text)
|
318 |
+
results.append({
|
319 |
+
'source': 'direct_input',
|
320 |
+
'content': cleaned_text,
|
321 |
+
'timestamp': datetime.now().isoformat()
|
322 |
+
})
|
323 |
+
|
324 |
+
# Generate output
|
325 |
+
if results:
|
326 |
+
output_dir = Path('output') / datetime.now().strftime('%Y-%m-%d')
|
327 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
328 |
+
output_path = output_dir / f'processed_{int(time.time())}.json'
|
329 |
+
|
330 |
+
with open(output_path, 'w', encoding='utf-8') as f:
|
331 |
+
json.dump(results, f, ensure_ascii=False, indent=2)
|
332 |
+
|
333 |
+
summary = f"Processed {len(results)} items successfully!"
|
334 |
+
json_data = json.dumps(results, indent=2) # Prepare JSON for QR code
|
335 |
+
return str(output_path), summary, json_data # Return JSON for editor
|
336 |
+
else:
|
337 |
+
return None, "No valid content to process.", ""
|
338 |
+
|
339 |
+
except Exception as e:
|
340 |
+
logger.error(f"Processing error: {e}")
|
341 |
+
return None, f"Error: {str(e)}", ""
|
342 |
+
|
343 |
+
def generate_qr_code(json_data):
|
344 |
+
"""Generate QR code from JSON data and return the file path."""
|
345 |
+
if json_data:
|
346 |
+
return generate_qr(json_data)
|
347 |
+
|
348 |
def create_interface():
|
349 |
"""Create a comprehensive Gradio interface with advanced features"""
|
350 |
css = """
|