Spaces:
Sleeping
Sleeping
import gradio as gr | |
import subprocess | |
import os | |
def run_katana(url): | |
# Set a custom configuration directory within /app | |
katana_config_dir = "/app/katana" | |
os.makedirs(katana_config_dir, exist_ok=True) | |
# Ensure the config file exists, or create a dummy one if needed | |
config_file_path = os.path.join(katana_config_dir, "config.yaml") | |
if not os.path.exists(config_file_path): | |
with open(config_file_path, 'w') as f: | |
f.write("# Dummy configuration\n") | |
output_file = "/app/urls.txt" # Use /app for writable directory | |
command = f"katana -config {config_file_path} -u {url} > {output_file}" | |
try: | |
subprocess.run(command, shell=True, check=True) | |
return output_file | |
except subprocess.CalledProcessError as e: | |
return f"Error running katana: {e}" | |
# Ensure the /app/flagged directory exists | |
os.makedirs("/app/flagged", exist_ok=True) | |
# Gradio interface | |
interface = gr.Interface( | |
fn=run_katana, | |
inputs="text", | |
outputs="file", | |
title="Katana URL Crawler", | |
description="Enter a URL to crawl with Katana.", | |
flagging_dir="/app/flagged" # Specify a writable directory for flagging | |
) | |
interface.launch(server_name="0.0.0.0", server_port=7860) | |