Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,41 +2,48 @@ import gradio as gr
|
|
2 |
import subprocess
|
3 |
import os
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
)
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import subprocess
|
3 |
import os
|
4 |
|
5 |
+
def crawl_website(url):
|
6 |
+
"""Crawls a website using Katana and saves the output to a text file."""
|
7 |
+
|
8 |
+
output_file = "katana_output.txt"
|
9 |
+
katana_command = [
|
10 |
+
"katana",
|
11 |
+
"-u", url,
|
12 |
+
"-o", output_file,
|
13 |
+
"-silent" # Only display output, no progress bars or logs
|
14 |
+
]
|
15 |
+
|
16 |
+
# Execute Katana command
|
17 |
+
try:
|
18 |
+
subprocess.run(katana_command, check=True)
|
19 |
+
except subprocess.CalledProcessError as e:
|
20 |
+
return f"Error running Katana: {e}", None
|
21 |
+
|
22 |
+
# Read output file content
|
23 |
+
with open(output_file, "r") as f:
|
24 |
+
output_content = f.read()
|
25 |
+
|
26 |
+
return output_content, output_file
|
27 |
+
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
gr.Markdown("## Website Crawler using Katana")
|
30 |
+
with gr.Row():
|
31 |
+
url_input = gr.Textbox(label="Enter Website URL")
|
32 |
+
output_text = gr.Textbox(label="Crawled Endpoints", lines=15)
|
33 |
+
download_button = gr.Button("Download Output File")
|
34 |
+
|
35 |
+
# Trigger crawling on button click
|
36 |
+
url_input.submit(
|
37 |
+
fn=crawl_website,
|
38 |
+
inputs=url_input,
|
39 |
+
outputs=[output_text, download_button]
|
40 |
+
)
|
41 |
+
|
42 |
+
# Download output file
|
43 |
+
download_button.click(
|
44 |
+
fn=lambda file: file,
|
45 |
+
inputs=download_button,
|
46 |
+
outputs=gr.File(label="Download Results")
|
47 |
+
)
|
48 |
+
|
49 |
+
demo.launch()
|