File size: 2,310 Bytes
8580646
 
 
 
 
 
 
 
 
 
1871623
 
 
8580646
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12bfe7e
 
8580646
 
12bfe7e
8580646
 
 
 
 
 
 
 
 
 
 
 
12bfe7e
 
8580646
 
 
 
 
 
 
 
 
27cbb2c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
import tempfile
import os
from sip_rtp_pcap_analyzer_with_visualization import SipRtpPcapAnalyzer

def analyze_pcap(pcap_file):
    # Create a temp output directory
    output_dir = tempfile.mkdtemp()

    # Save uploaded file to a temp file
    temp_pcap_path = pcap_file #os.path.join(output_dir, pcap_file.name)
    #with open(temp_pcap_path, "wb") as f:
    #    f.write(pcap_file.read())

    # Run analysis with visualization
    analyzer = SipRtpPcapAnalyzer(
        pcap_file=temp_pcap_path,
        output_dir=output_dir,
        visualize=True
    )
    analyzer.analyze()

    # Get the summary text output
    from io import StringIO
    import sys
    old_stdout = sys.stdout
    sys.stdout = mystdout = StringIO()
    analyzer.print_results()
    sys.stdout = old_stdout
    result_text = mystdout.getvalue()

    # Prepare outputs
    html_report_path = os.path.join(output_dir, "sip_rtp_report.html")
    rtp_graphs = [os.path.join(output_dir, f) for f in os.listdir(output_dir) if f.startswith("rtp_visualization") and f.endswith(".png")]
    sequence_diagrams = [os.path.join(output_dir, f) for f in os.listdir(output_dir) if f.startswith("sip_sequence") and f.endswith(".png")]
    dashboard = os.path.join(output_dir, "call_quality_dashboard.png")

    return result_text, html_report_path, sequence_diagrams, rtp_graphs, dashboard

with gr.Blocks(title="SIP & RTP PCAP Analyzer") as demo:
    gr.Markdown("""

    # SIP and RTP Analyzer

    Upload a PCAP file to analyze SIP calls and RTP streams. Visualizations and call quality metrics will be shown.

    """)
    with gr.Row():
        pcap_input = gr.File(label="Upload PCAP/PCAPNG File")
        run_btn = gr.Button("Analyze")

    result_text = gr.Textbox(label="Analysis Summary", lines=15)
    html_report = gr.File(label="Download HTML Report")
    sequence_images = gr.Gallery(label="SIP Sequence Diagrams")
    rtp_images = gr.Gallery(label="RTP Stream Visualizations")
    dashboard_image = gr.Image(label="Call Quality Dashboard")

    run_btn.click(
        fn=analyze_pcap,
        inputs=pcap_input,
        outputs=[result_text, html_report, sequence_images, rtp_images, dashboard_image]
    )

if __name__ == "__main__":
    demo.launch()