Spaces:
Sleeping
Sleeping
import subprocess | |
import gradio as gr | |
import tempfile | |
import os | |
import io | |
def run_katana(url): | |
try: | |
result = subprocess.run(["katana", "-u", url], capture_output=True, text=True, check=True) | |
# Create an in-memory file-like object | |
buffer = io.StringIO(result.stdout) | |
# Generate a filename based on the URL | |
filename = f"katana_results_{url.replace('://', '_').replace('/', '_')}.txt" | |
return result.stdout, (buffer, filename) | |
except Exception as e: | |
return str(e), None | |
def process_and_display(url): | |
result, file_data = run_katana(url) | |
if file_data: | |
return result, file_data | |
else: | |
return result, None | |
iface = gr.Interface( | |
fn=process_and_display, | |
inputs="text", | |
outputs=[ | |
gr.Textbox(label="Crawl Results"), | |
gr.File(label="Download Results", file_count="single") | |
], | |
title="Katana Crawler", | |
description="Enter a URL to crawl using Katana. Results will be displayed and available for download.", | |
allow_flagging="never" | |
) | |
iface.launch(server_name="0.0.0.0", server_port=7860) | |