binuser007 commited on
Commit
e71a6e3
·
verified ·
1 Parent(s): 38fafcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -2,26 +2,28 @@ import subprocess
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
 
 
2
  import gradio as gr
3
  import tempfile
4
  import os
5
+
6
 
7
  def run_katana(url):
8
+ try:
9
+ # Create a temporary file to store the results
10
+ with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.txt') as temp_file:
11
+ # Run Katana and save output to the temporary file
12
+ subprocess.run(["katana", "-u", url, "-o", temp_file.name], check=True)
13
+
14
+ # Read the contents of the file
15
+ temp_file.seek(0)
16
+ result = temp_file.read()
17
+
18
+ # Return the result and the path to the temporary file
19
+ return result, temp_file.name
20
+ except Exception as e:
21
  return str(e), None
22
 
23
  def process_and_display(url):
24
+ result, file_path = run_katana(url)
25
+ if file_path:
26
+ return result, file_path
27
  else:
28
  return result, None
29