Spaces:
Sleeping
Sleeping
Upload graphs.py
Browse files
graphs.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import matplotlib.pyplot as plt
|
| 2 |
+
import tempfile
|
| 3 |
+
import os
|
| 4 |
+
import uuid
|
| 5 |
+
|
| 6 |
+
def create_graphs(chunk_lengths, retrieved_len, summary_len, stage_times):
|
| 7 |
+
temp_dir = tempfile.gettempdir()
|
| 8 |
+
uid = str(uuid.uuid4())
|
| 9 |
+
|
| 10 |
+
# Graph 1: Pipeline stage execution time
|
| 11 |
+
plt.figure(figsize=(8, 5))
|
| 12 |
+
plt.bar(stage_times.keys(), stage_times.values())
|
| 13 |
+
plt.xticks(rotation=30)
|
| 14 |
+
plt.title("Pipeline Stage Execution Time", fontsize=14)
|
| 15 |
+
plt.xlabel("Pipeline Stage")
|
| 16 |
+
plt.ylabel("Time (seconds)")
|
| 17 |
+
plt.grid(axis="y", linestyle="--", alpha=0.7)
|
| 18 |
+
plt.tight_layout()
|
| 19 |
+
g1 = os.path.join(temp_dir, f"g1_{uid}.png")
|
| 20 |
+
plt.savefig(g1)
|
| 21 |
+
plt.close()
|
| 22 |
+
|
| 23 |
+
# Graph 2: Chunk length distribution
|
| 24 |
+
plt.figure(figsize=(8, 5))
|
| 25 |
+
plt.hist(chunk_lengths, bins=20)
|
| 26 |
+
plt.title("Chunk Length Distribution", fontsize=14)
|
| 27 |
+
plt.xlabel("Chunk Length (words)")
|
| 28 |
+
plt.ylabel("Frequency")
|
| 29 |
+
plt.grid(axis="y", linestyle="--", alpha=0.7)
|
| 30 |
+
plt.tight_layout()
|
| 31 |
+
g2 = os.path.join(temp_dir, f"g2_{uid}.png")
|
| 32 |
+
plt.savefig(g2)
|
| 33 |
+
plt.close()
|
| 34 |
+
|
| 35 |
+
# Graph 3: Retrieved vs summary length
|
| 36 |
+
plt.figure(figsize=(6, 5))
|
| 37 |
+
plt.bar(["Retrieved Text", "Summary"], [retrieved_len, summary_len])
|
| 38 |
+
plt.title("Retrieved vs Summary Length", fontsize=14)
|
| 39 |
+
plt.xlabel("Text Type")
|
| 40 |
+
plt.ylabel("Word Count")
|
| 41 |
+
plt.grid(axis="y", linestyle="--", alpha=0.7)
|
| 42 |
+
plt.tight_layout()
|
| 43 |
+
g3 = os.path.join(temp_dir, f"g3_{uid}.png")
|
| 44 |
+
plt.savefig(g3)
|
| 45 |
+
plt.close()
|
| 46 |
+
|
| 47 |
+
return g1, g2, g3
|