acecalisto3 commited on
Commit
6ec7960
·
verified ·
1 Parent(s): 7eff2b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -12
app.py CHANGED
@@ -4,12 +4,8 @@ import re
4
  import time
5
  import logging
6
  import mimetypes
7
- import concurrent.futures
8
- import string
9
- import zipfile
10
  import tempfile
11
  from datetime import datetime
12
- from typing import List, Dict, Optional, Union
13
  from pathlib import Path
14
  from urllib.parse import urlparse
15
 
@@ -19,8 +15,8 @@ import gradio as gr
19
  from diskcache import Cache
20
  from bs4 import BeautifulSoup
21
  from fake_useragent import UserAgent
22
- from ratelimit import limits, sleep_and_retry
23
  from cleantext import clean
 
24
 
25
  # Setup logging with detailed configuration
26
  logging.basicConfig(
@@ -262,6 +258,13 @@ def _process_single_file(self, file) -> List[Dict]:
262
  logger.error(f"File processing error: {e}")
263
  return []
264
 
 
 
 
 
 
 
 
265
  def create_interface():
266
  """Create a comprehensive Gradio interface with advanced features"""
267
 
@@ -294,12 +297,31 @@ def create_interface():
294
  placeholder="Paste your text here..."
295
  )
296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  process_btn = gr.Button("Process Input", variant="primary")
 
298
 
299
  output_text = gr.Textbox(label="Processing Results", interactive=False)
300
  output_file = gr.File(label="Processed Output")
 
301
 
302
- def process_all_inputs(urls, file, text):
303
  """Process all input types with progress tracking"""
304
  try:
305
  processor = URLProcessor()
@@ -346,19 +368,31 @@ def create_interface():
346
  json.dump(results, f, ensure_ascii=False, indent=2)
347
 
348
  summary = f"Processed {len(results)} items successfully!"
349
- # Convert Path object to string here
350
- return str(output_path), summary
351
  else:
352
- return None, "No valid content to process."
353
 
354
  except Exception as e:
355
  logger.error(f"Processing error: {e}")
356
- return None, f"Error: {str(e)}"
 
 
 
 
 
 
357
 
358
  process_btn.click(
359
  process_all_inputs,
360
- inputs=[url_input, file_input, text_input],
361
- outputs=[output_file, output_text]
 
 
 
 
 
 
362
  )
363
 
364
  gr.Markdown("""
@@ -366,6 +400,8 @@ def create_interface():
366
  - **URL Processing**: Enter valid HTTP/HTTPS URLs
367
  - **File Input**: Upload text files or ZIP archives
368
  - **Text Input**: Direct text processing
 
 
369
  - Advanced cleaning and validation included
370
  """)
371
 
@@ -387,5 +423,6 @@ def main():
387
  inbrowser=True,
388
  debug=True
389
  )
 
390
  if __name__ == "__main__":
391
  main()
 
4
  import time
5
  import logging
6
  import mimetypes
 
 
 
7
  import tempfile
8
  from datetime import datetime
 
9
  from pathlib import Path
10
  from urllib.parse import urlparse
11
 
 
15
  from diskcache import Cache
16
  from bs4 import BeautifulSoup
17
  from fake_useragent import UserAgent
 
18
  from cleantext import clean
19
+ import qrcode
20
 
21
  # Setup logging with detailed configuration
22
  logging.basicConfig(
 
258
  logger.error(f"File processing error: {e}")
259
  return []
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)
266
+ return qr_path
267
+
268
  def create_interface():
269
  """Create a comprehensive Gradio interface with advanced features"""
270
 
 
297
  placeholder="Paste your text here..."
298
  )
299
 
300
+ with gr.Tab("JSON Editor"):
301
+ json_editor = gr.Textbox(
302
+ label="JSON Editor",
303
+ lines=20,
304
+ placeholder="View and edit your JSON data here...",
305
+ interactive=True,
306
+ elem_id="json-editor" # Optional: for custom styling
307
+ )
308
+
309
+ with gr.Tab("Scratchpad"):
310
+ scratchpad = gr.Textbox(
311
+ label="Scratchpad",
312
+ lines=10,
313
+ placeholder="Quick notes or text collections...",
314
+ interactive=True
315
+ )
316
+
317
  process_btn = gr.Button("Process Input", variant="primary")
318
+ qr_btn = gr.Button("Generate QR Code", variant="secondary")
319
 
320
  output_text = gr.Textbox(label="Processing Results", interactive=False)
321
  output_file = gr.File(label="Processed Output")
322
+ qr_output = gr.Image(label="QR Code", type="filepath") # To display the generated QR code
323
 
324
+ def process_all_inputs(urls, file, text, notes):
325
  """Process all input types with progress tracking"""
326
  try:
327
  processor = URLProcessor()
 
368
  json.dump(results, f, ensure_ascii=False, indent=2)
369
 
370
  summary = f"Processed {len(results)} items successfully!"
371
+ json_data = json.dumps(results, indent=2) # Prepare JSON for QR code
372
+ return str(output_path), summary, json_data # Return JSON for editor
373
  else:
374
+ return None, "No valid content to process.", ""
375
 
376
  except Exception as e:
377
  logger.error(f"Processing error: {e}")
378
+ return None, f"Error: {str(e)}", ""
379
+
380
+ def generate_qr(json_data):
381
+ """Generate QR code from JSON data and return the file path."""
382
+ if json_data:
383
+ return generate_qr_code(json_data)
384
+ return None
385
 
386
  process_btn.click(
387
  process_all_inputs,
388
+ inputs=[url_input, file_input, text_input, scratchpad],
389
+ outputs=[output_file, output_text, json_editor] # Update outputs to include JSON editor
390
+ )
391
+
392
+ qr_btn.click(
393
+ generate_qr,
394
+ inputs=json_editor,
395
+ outputs=qr_output
396
  )
397
 
398
  gr.Markdown("""
 
400
  - **URL Processing**: Enter valid HTTP/HTTPS URLs
401
  - **File Input**: Upload text files or ZIP archives
402
  - **Text Input**: Direct text processing
403
+ - **JSON Editor**: View and edit your JSON data
404
+ - **Scratchpad**: Quick notes or text collections
405
  - Advanced cleaning and validation included
406
  """)
407
 
 
423
  inbrowser=True,
424
  debug=True
425
  )
426
+
427
  if __name__ == "__main__":
428
  main()