Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import io
|
3 |
+
import tempfile
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
def run_katana(url, crawl_type):
|
7 |
+
try:
|
8 |
+
if crawl_type == "All URLs":
|
9 |
+
command = ["katana", "-u", url]
|
10 |
+
else: # Subkeyword URLs
|
11 |
+
command = [
|
12 |
+
"katana",
|
13 |
+
"-u", url,
|
14 |
+
"-cs", f"^{url}.*",
|
15 |
+
"-depth", "5",
|
16 |
+
"-jc"
|
17 |
+
]
|
18 |
+
|
19 |
+
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
20 |
+
|
21 |
+
# Create an in-memory file-like object
|
22 |
+
buffer = io.StringIO(result.stdout)
|
23 |
+
|
24 |
+
return result.stdout, buffer
|
25 |
+
except Exception as e:
|
26 |
+
return str(e), None
|
27 |
+
```
|
28 |
+
|
29 |
+
Modify the process_and_display function to include the crawl_type parameter
|
30 |
+
```python
|
31 |
+
def process_and_display(url, crawl_type):
|
32 |
+
result, file_data = run_katana(url, crawl_type)
|
33 |
+
if file_data:
|
34 |
+
# Create a temporary file with a meaningful name
|
35 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.txt')
|
36 |
+
temp_file.write(file_data.getvalue().encode('utf-8'))
|
37 |
+
temp_file.close()
|
38 |
+
|
39 |
+
# Return the result and the path to the temporary file
|
40 |
+
return result, temp_file.name
|
41 |
+
else:
|
42 |
+
return result, None
|
43 |
+
```
|
44 |
+
|
45 |
+
#Update the Gradio interface to include the dropdown menu
|
46 |
+
|
47 |
+
|
48 |
+
iface = gr.Interface(
|
49 |
+
fn=process_and_display,
|
50 |
+
inputs=[
|
51 |
+
gr.Textbox(label="Enter URL"),
|
52 |
+
gr.Dropdown(choices=["All URLs", "Subkeyword URLs"], label="Crawl Type")
|
53 |
+
],
|
54 |
+
outputs=[
|
55 |
+
gr.Textbox(label="Crawl Results"),
|
56 |
+
gr.File(label="Download Results")
|
57 |
+
],
|
58 |
+
title="Katana Crawler",
|
59 |
+
description="Enter a URL to crawl using Katana. Select the crawl type and results will be displayed and available for download.",
|
60 |
+
allow_flagging="never"
|
61 |
+
)
|
62 |
+
|
63 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|