Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,7 @@ def get_llm_opinion(prompt, generator):
|
|
| 36 |
def process_file(pcap_file):
|
| 37 |
"""
|
| 38 |
This function is called when user clicks the 'Analyze File' button.
|
| 39 |
-
- pcap_file:
|
| 40 |
Returns:
|
| 41 |
- a textual summary (analysis + call flow)
|
| 42 |
- the dictionary of calls_by_id (saved in Gradio state so we can pass them to the LLM)
|
|
@@ -44,10 +44,19 @@ def process_file(pcap_file):
|
|
| 44 |
if not pcap_file:
|
| 45 |
return "No file uploaded.", {}
|
| 46 |
|
| 47 |
-
#
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
with open(temp_filename, "wb") as f:
|
| 50 |
-
f.write(
|
| 51 |
|
| 52 |
# 1) Parse the PCAP
|
| 53 |
calls_by_id = parse_pcap(temp_filename)
|
|
|
|
| 36 |
def process_file(pcap_file):
|
| 37 |
"""
|
| 38 |
This function is called when user clicks the 'Analyze File' button.
|
| 39 |
+
- pcap_file: A dictionary returned by Gradio's File component.
|
| 40 |
Returns:
|
| 41 |
- a textual summary (analysis + call flow)
|
| 42 |
- the dictionary of calls_by_id (saved in Gradio state so we can pass them to the LLM)
|
|
|
|
| 44 |
if not pcap_file:
|
| 45 |
return "No file uploaded.", {}
|
| 46 |
|
| 47 |
+
# In newer Gradio versions, pcap_file is a dict:
|
| 48 |
+
# {
|
| 49 |
+
# "name": "path or random name",
|
| 50 |
+
# "orig_name": "original_filename.pcap",
|
| 51 |
+
# "data": b"raw bytes of the file",
|
| 52 |
+
# ...
|
| 53 |
+
# }
|
| 54 |
+
temp_filename = pcap_file["name"]
|
| 55 |
+
raw_data = pcap_file["data"]
|
| 56 |
+
|
| 57 |
+
# Write the file bytes to disk
|
| 58 |
with open(temp_filename, "wb") as f:
|
| 59 |
+
f.write(raw_data)
|
| 60 |
|
| 61 |
# 1) Parse the PCAP
|
| 62 |
calls_by_id = parse_pcap(temp_filename)
|