File size: 1,534 Bytes
f9ddc4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import matplotlib.pyplot as plt
import tempfile
import os
import uuid

def create_graphs(chunk_lengths, retrieved_len, summary_len, stage_times):
    temp_dir = tempfile.gettempdir()
    uid = str(uuid.uuid4())

    # Graph 1: Pipeline stage execution time
    plt.figure(figsize=(8, 5))
    plt.bar(stage_times.keys(), stage_times.values())
    plt.xticks(rotation=30)
    plt.title("Pipeline Stage Execution Time", fontsize=14)
    plt.xlabel("Pipeline Stage")
    plt.ylabel("Time (seconds)")
    plt.grid(axis="y", linestyle="--", alpha=0.7)
    plt.tight_layout()
    g1 = os.path.join(temp_dir, f"g1_{uid}.png")
    plt.savefig(g1)
    plt.close()

    # Graph 2: Chunk length distribution
    plt.figure(figsize=(8, 5))
    plt.hist(chunk_lengths, bins=20)
    plt.title("Chunk Length Distribution", fontsize=14)
    plt.xlabel("Chunk Length (words)")
    plt.ylabel("Frequency")
    plt.grid(axis="y", linestyle="--", alpha=0.7)
    plt.tight_layout()
    g2 = os.path.join(temp_dir, f"g2_{uid}.png")
    plt.savefig(g2)
    plt.close()

    # Graph 3: Retrieved vs summary length
    plt.figure(figsize=(6, 5))
    plt.bar(["Retrieved Text", "Summary"], [retrieved_len, summary_len])
    plt.title("Retrieved vs Summary Length", fontsize=14)
    plt.xlabel("Text Type")
    plt.ylabel("Word Count")
    plt.grid(axis="y", linestyle="--", alpha=0.7)
    plt.tight_layout()
    g3 = os.path.join(temp_dir, f"g3_{uid}.png")
    plt.savefig(g3)
    plt.close()

    return g1, g2, g3