Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,40 @@
|
|
1 |
-
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 |
-
# 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()
|
|
|
|
|
1 |
import subprocess
|
2 |
+
import gradio as gr
|
3 |
+
import tempfile
|
4 |
import os
|
5 |
|
6 |
+
def run_katana(url):
|
7 |
+
try:
|
8 |
+
# Create a temporary file to store the results
|
9 |
+
with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.txt') as temp_file:
|
10 |
+
# Run Katana and save output to the temporary file
|
11 |
+
subprocess.run(["katana", "-u", url, "-o", temp_file.name], check=True)
|
12 |
+
|
13 |
+
# Read the contents of the file
|
14 |
+
temp_file.seek(0)
|
15 |
+
result = temp_file.read()
|
16 |
+
|
17 |
+
# Return the result and the path to the temporary file
|
18 |
+
return result, temp_file.name
|
19 |
+
except Exception as e:
|
20 |
+
return str(e), None
|
21 |
+
|
22 |
+
def process_and_display(url):
|
23 |
+
result, file_path = run_katana(url)
|
24 |
+
if file_path:
|
25 |
+
return result, file_path
|
26 |
+
else:
|
27 |
+
return result, None
|
28 |
+
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=process_and_display,
|
31 |
+
inputs="text",
|
32 |
+
outputs=[
|
33 |
+
gr.Textbox(label="Crawl Results"),
|
34 |
+
gr.File(label="Download Results")
|
35 |
+
],
|
36 |
+
title="Katana Crawler",
|
37 |
+
description="Enter a URL to crawl using Katana. Results will be displayed and available for download."
|
38 |
+
)
|
39 |
+
|
40 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|