Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
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 |
-
|
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 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
|
404 |
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
|
415 |
-
|
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
|