import re
import matplotlib.pyplot as plt

# Read the text from a file
with open(r"F:\voice clone tutorial\DL-Art-School\experiments\bigtom\train_bigtom_230509-021906.log", 'r') as file:
    text = file.read()

pattern = r"loss_text_ce:\s(\d+.\d+e[+-]\d+)\sloss_mel_ce:\s(\d+.\d+e[+-]\d+)\sloss_gpt_total:\s(\d+.\d+e[+-]\d+)"

matches = re.findall(pattern, text)

loss_text_ce = [float(x[0]) for x in matches]
loss_mel_ce = [float(x[1]) for x in matches]
loss_gpt_total = [float(x[2]) for x in matches]

plt.figure(figsize=(10,6))

plt.plot(loss_text_ce, label="loss_text_ce")
plt.plot(loss_mel_ce, label="loss_mel_ce")
plt.plot(loss_gpt_total, label="loss_gpt_total")

plt.xlabel('Time step')
plt.ylabel('Loss value')
plt.title('Loss values over time')
plt.legend()

plt.show()
