binuser007 commited on
Commit
204395e
·
verified ·
1 Parent(s): 846cb56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
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
- 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
 
 
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