acecalisto3 commited on
Commit
97734ac
·
verified ·
1 Parent(s): 0b2fd02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -37
app.py CHANGED
@@ -18,6 +18,7 @@ from bs4 import BeautifulSoup
18
  from fake_useragent import UserAgent
19
  from cleantext import clean
20
  import qrcode
 
21
  import zipfile
22
  import zipfile36 as zipfile
23
 
@@ -253,7 +254,7 @@ class FileProcessor:
253
  except Exception as e:
254
  logger.error(f"File processing error: {e}")
255
  return []
256
- def generate_qr_code(json_data):
257
  """Generate a QR code from JSON data."""
258
  qr = qrcode.make(json_data)
259
  qr_path = "output/qr_code.png"
@@ -316,7 +317,7 @@ def create_interface():
316
  output_file = gr.File(label="Processed Output")
317
  qr_output = gr.Image(label="QR Code", type="filepath") # To display the generated QR code
318
 
319
- def process_all_inputs(urls, file, text, notes):
320
  """Process all input types with progress tracking"""
321
  try:
322
  processor = URLProcessor()
@@ -373,46 +374,46 @@ def create_interface():
373
  return None, f"Error: {str(e)}", ""
374
 
375
 
376
- def generate_qr(json_data):
377
- """Generate QR code from JSON data and return the file path."""
378
- qr = qrcode.QRCode(
379
- version=40, # Force maximum version
380
- error_correction=qrcode.constants.ERROR_CORRECT_L, # Use lower error correction
381
- box_size=10,
382
- border=4,
383
- )
384
- qr.add_data(json_data)
385
- qr.make(fit=True)
386
- return qr.make_image(fill_color="black", back_color="white")
387
-
388
- if json_data:
389
- return generate_qr_code(json_data)
390
- return None
391
 
392
- process_btn.click(
393
- process_all_inputs,
394
- inputs=[url_input, file_input, text_input, scratchpad],
395
- outputs=[output_file, output_text, json_editor] # Update outputs to include JSON editor
396
- )
397
 
398
- qr_btn.click(
399
- generate_qr,
400
- inputs=json_editor,
401
- outputs=qr_output
402
- )
403
 
404
 
405
- gr.Markdown("""
406
- ### Usage Guidelines
407
- - **URL Processing**: Enter valid HTTP/HTTPS URLs
408
- - **File Input**: Upload text files or ZIP archives
409
- - **Text Input**: Direct text processing
410
- - **JSON Editor**: View and edit your JSON data
411
- - **Scratchpad**: Quick notes or text collections
412
- - Advanced cleaning and validation included
413
- """)
414
 
415
- return interface
416
 
417
  def main():
418
  # Configure system settings
 
18
  from fake_useragent import UserAgent
19
  from cleantext import clean
20
  import qrcode
21
+ import
22
  import zipfile
23
  import zipfile36 as zipfile
24
 
 
254
  except Exception as e:
255
  logger.error(f"File processing error: {e}")
256
  return []
257
+ generate_qr_code(json_data):
258
  """Generate a QR code from JSON data."""
259
  qr = qrcode.make(json_data)
260
  qr_path = "output/qr_code.png"
 
317
  output_file = gr.File(label="Processed Output")
318
  qr_output = gr.Image(label="QR Code", type="filepath") # To display the generated QR code
319
 
320
+ def process_all_inputs(urls, file, text, notes):
321
  """Process all input types with progress tracking"""
322
  try:
323
  processor = URLProcessor()
 
374
  return None, f"Error: {str(e)}", ""
375
 
376
 
377
+ def generate_qr(json_data):
378
+ """Generate QR code from JSON data and return the file path."""
379
+ qr = qrcode.QRCode(
380
+ version=40, # Force maximum version
381
+ error_correction=qrcode.constants.ERROR_CORRECT_L, # Use lower error correction
382
+ box_size=10,
383
+ border=4,
384
+ )
385
+ qr.add_data(json_data)
386
+ qr.make(fit=True)
387
+ return qr.make_image(fill_color="black", back_color="white")
388
+
389
+ if json_data:
390
+ return generate_qr_code(json_data)
391
+ return None
392
 
393
+ process_btn.click(
394
+ process_all_inputs,
395
+ inputs=[url_input, file_input, text_input, scratchpad],
396
+ outputs=[output_file, output_text, json_editor] # Update outputs to include JSON editor
397
+ )
398
 
399
+ qr_btn.click(
400
+ generate_qr,
401
+ inputs=json_editor,
402
+ outputs=qr_output
403
+ )
404
 
405
 
406
+ gr.Markdown("""
407
+ ### Usage Guidelines
408
+ - **URL Processing**: Enter valid HTTP/HTTPS URLs
409
+ - **File Input**: Upload text files or ZIP archives
410
+ - **Text Input**: Direct text processing
411
+ - **JSON Editor**: View and edit your JSON data
412
+ - **Scratchpad**: Quick notes or text collections
413
+ - Advanced cleaning and validation included
414
+ """)
415
 
416
+ return interface
417
 
418
  def main():
419
  # Configure system settings