Added code to visual her best dreams
This commit is contained in:
parent
7d1f2ac3fa
commit
6eb63097fa
10
dashboard.py
10
dashboard.py
@ -12,6 +12,13 @@ def tail(filepath, num_lines=10):
|
|||||||
return f.readlines()[-num_lines:]
|
return f.readlines()[-num_lines:]
|
||||||
|
|
||||||
|
|
||||||
|
def get_best_dream():
|
||||||
|
if not os.path.exists("logs/best_dream.txt"):
|
||||||
|
return "No high-scoring dream yet."
|
||||||
|
with open("logs/best_dream.txt", encoding="utf-8") as f:
|
||||||
|
return f.read().strip()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
vocab_size = 0
|
vocab_size = 0
|
||||||
@ -22,6 +29,7 @@ def home():
|
|||||||
dreams = [line.strip() for line in tail("logs/dreams.log", 10)]
|
dreams = [line.strip() for line in tail("logs/dreams.log", 10)]
|
||||||
messages = [line.strip() for line in tail("logs/messages.log", 10)]
|
messages = [line.strip() for line in tail("logs/messages.log", 10)]
|
||||||
errors = [line.strip() for line in tail("logs/error.log", 15)]
|
errors = [line.strip() for line in tail("logs/error.log", 15)]
|
||||||
|
best_dream = get_best_dream()
|
||||||
|
|
||||||
return render_template_string("""
|
return render_template_string("""
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@ -60,6 +68,8 @@ def home():
|
|||||||
{{ err }}
|
{{ err }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</pre>
|
</pre>
|
||||||
|
<h3>🏆 Highest Scoring Dream</h3>
|
||||||
|
<p><b>{{ best_dream }}</b></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
""", dreams=dreams[::-1], messages=messages[::-1], errors=errors[::-1], vocab_size=vocab_size)
|
""", dreams=dreams[::-1], messages=messages[::-1], errors=errors[::-1], vocab_size=vocab_size)
|
||||||
|
@ -19,6 +19,7 @@ class RubyTrainer:
|
|||||||
self.criterion = torch.nn.CrossEntropyLoss()
|
self.criterion = torch.nn.CrossEntropyLoss()
|
||||||
|
|
||||||
self.rebuild_model_if_needed()
|
self.rebuild_model_if_needed()
|
||||||
|
self.best_dream = ("", 0.0)
|
||||||
|
|
||||||
def rebuild_model_if_needed(self):
|
def rebuild_model_if_needed(self):
|
||||||
vocab_size = len(self.tokenizer.vocab)
|
vocab_size = len(self.tokenizer.vocab)
|
||||||
@ -156,7 +157,8 @@ class RubyTrainer:
|
|||||||
|
|
||||||
score_raw = self.score_sentence(raw)
|
score_raw = self.score_sentence(raw)
|
||||||
score_re = self.score_sentence(rephrased)
|
score_re = self.score_sentence(rephrased)
|
||||||
|
if score_re >= self.best_dream[1]:
|
||||||
|
self.best_dream = (rephrased.strip(), score_re)
|
||||||
final = rephrased if score_re >= score_raw else raw
|
final = rephrased if score_re >= score_raw else raw
|
||||||
|
|
||||||
self.train_on_tokens_from_text(final)
|
self.train_on_tokens_from_text(final)
|
||||||
@ -182,6 +184,8 @@ class RubyTrainer:
|
|||||||
f.write(f"{datetime.utcnow().isoformat()} | Ruby | {t}\n")
|
f.write(f"{datetime.utcnow().isoformat()} | Ruby | {t}\n")
|
||||||
|
|
||||||
print(f"[DAYDREAM] Complete. {len(thoughts)} thoughts imagined.")
|
print(f"[DAYDREAM] Complete. {len(thoughts)} thoughts imagined.")
|
||||||
|
with open("logs/best_dream.txt", "w", encoding="utf-8") as f:
|
||||||
|
f.write(f"{self.best_dream[1]:.2f} | {self.best_dream[0]}\n")
|
||||||
|
|
||||||
if say_thought and thoughts:
|
if say_thought and thoughts:
|
||||||
return thoughts[-1]
|
return thoughts[-1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user