Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,27 +2,26 @@ import subprocess
|
|
| 2 |
import gradio as gr
|
| 3 |
import tempfile
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
def run_katana(url):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 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,
|
| 24 |
-
if
|
| 25 |
-
return result,
|
| 26 |
else:
|
| 27 |
return result, None
|
| 28 |
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import tempfile
|
| 4 |
import os
|
| 5 |
+
import io
|
| 6 |
|
| 7 |
def run_katana(url):
|
| 8 |
+
try:
|
| 9 |
+
result = subprocess.run(["katana", "-u", url], capture_output=True, text=True, check=True)
|
| 10 |
+
|
| 11 |
+
# Create an in-memory file-like object
|
| 12 |
+
buffer = io.StringIO(result.stdout)
|
| 13 |
+
|
| 14 |
+
# Generate a filename based on the URL
|
| 15 |
+
filename = f"katana_results_{url.replace('://', '_').replace('/', '_')}.txt"
|
| 16 |
+
|
| 17 |
+
return result.stdout, (buffer, filename)
|
|
|
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
return str(e), None
|
| 20 |
|
| 21 |
def process_and_display(url):
|
| 22 |
+
result, file_data = run_katana(url)
|
| 23 |
+
if file_data:
|
| 24 |
+
return result, file_data
|
| 25 |
else:
|
| 26 |
return result, None
|
| 27 |
|