mirror of
https://github.com/SakanaAI/doc-to-lora.git
synced 2026-07-23 17:01:04 +02:00
first attemp webui
This commit is contained in:
parent
6bff905c37
commit
9776395bfd
4 changed files with 388 additions and 0 deletions
101
webui/app.py
Normal file
101
webui/app.py
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
import os
|
||||
import json
|
||||
from flask import Flask, render_template, request, abort
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
TRAIN_OUTPUTS_DIR = "train_outputs"
|
||||
|
||||
|
||||
def get_run_data(run_path):
|
||||
"""
|
||||
Loads and processes data from all_results.json for a given run.
|
||||
|
||||
Args:
|
||||
run_path: Path to the directory containing the all_results.json file.
|
||||
|
||||
Returns:
|
||||
A dictionary containing the grouped results data.
|
||||
"""
|
||||
results_file = os.path.join(run_path, "all_results.json")
|
||||
try:
|
||||
with open(results_file, "r") as f:
|
||||
data = json.load(f)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
grouped_data = {}
|
||||
for key, value in data.items():
|
||||
if isinstance(value, float):
|
||||
value = round(value, 4)
|
||||
prefix = key.split("_")[0]
|
||||
if prefix not in grouped_data:
|
||||
grouped_data[prefix] = {}
|
||||
grouped_data[prefix][key] = value
|
||||
|
||||
return grouped_data
|
||||
|
||||
|
||||
def get_generated_text_data(run_path):
|
||||
"""
|
||||
Loads generated text data from test_generated_text.jsonl and val_generated_text.jsonl.
|
||||
|
||||
Args:
|
||||
run_path: Path to the directory containing the .jsonl files.
|
||||
|
||||
Returns:
|
||||
A dictionary containing the generated text data for "test" and "val".
|
||||
"""
|
||||
generated_data = {}
|
||||
for split in ["test", "val"]:
|
||||
filename = f"{split}_generated_text.jsonl"
|
||||
filepath = os.path.join(run_path, filename)
|
||||
try:
|
||||
with open(filepath, "r") as f:
|
||||
lines = f.readlines()
|
||||
data = [json.loads(line) for line in lines]
|
||||
generated_data[split] = data
|
||||
except FileNotFoundError:
|
||||
generated_data[split] = None
|
||||
return generated_data
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
"""
|
||||
Displays a dropdown list of training runs.
|
||||
"""
|
||||
runs = [
|
||||
d
|
||||
for d in os.listdir(TRAIN_OUTPUTS_DIR)
|
||||
if os.path.isdir(os.path.join(TRAIN_OUTPUTS_DIR, d))
|
||||
]
|
||||
runs.sort(
|
||||
key=lambda d: os.path.getctime(os.path.join(TRAIN_OUTPUTS_DIR, d)),
|
||||
reverse=True,
|
||||
)
|
||||
return render_template("index.html", runs=runs)
|
||||
|
||||
|
||||
@app.route("/visualize/<run>")
|
||||
def visualize(run):
|
||||
"""
|
||||
Displays the results from all_results.json and the generated text data.
|
||||
"""
|
||||
logdir = os.path.join(TRAIN_OUTPUTS_DIR, run)
|
||||
if not os.path.isdir(logdir):
|
||||
abort(404, description=f"Run '{run}' not found.")
|
||||
|
||||
data = get_run_data(logdir)
|
||||
if data is None:
|
||||
abort(404, description=f"'all_results.json' not found in '{run}'.")
|
||||
|
||||
generated_data = get_generated_text_data(logdir)
|
||||
|
||||
return render_template(
|
||||
"visualize.html", run=run, data=data, generated_data=generated_data
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
22
webui/templates/base.html
Normal file
22
webui/templates/base.html
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>{% block title %}My Web App{% endblock %}</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap');
|
||||
|
||||
body {
|
||||
font-family: 'DM Sans', sans-serif;
|
||||
}
|
||||
|
||||
/* Add any other common styles here */
|
||||
</style>
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
12
webui/templates/index.html
Normal file
12
webui/templates/index.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Training Run Visualizer{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Select a Training Run</h1>
|
||||
<ul>
|
||||
{% for run in runs %}
|
||||
<li><a href="{{ url_for('visualize', run=run) }}">{{ run }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
253
webui/templates/visualize.html
Normal file
253
webui/templates/visualize.html
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Training Run Visualization: {{ run }}{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<style>
|
||||
table {
|
||||
width: 80%;
|
||||
margin: 20px auto;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
.group-header {
|
||||
background-color: #e0e0e0;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.column {
|
||||
flex: 0 0 auto;
|
||||
padding: 20px;
|
||||
background-color: #f8f8f8;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 10px;
|
||||
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.generated-text-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.generated-text-controls {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.generated-text-controls button {
|
||||
margin: 0;
|
||||
padding: 8px 16px;
|
||||
background-color: #4CAF50;
|
||||
/* Green */
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.generated-text-controls button:hover {
|
||||
background-color: #367c39;
|
||||
/* Darker green */
|
||||
}
|
||||
|
||||
.generated-text-controls input {
|
||||
width: 80px;
|
||||
padding: 8px;
|
||||
margin: 0;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.generated-text-display {
|
||||
min-height: 150px;
|
||||
}
|
||||
|
||||
.generated-text-display p span {
|
||||
display: block;
|
||||
overflow-y: auto;
|
||||
max-height: 100px;
|
||||
/* Adjust as needed */
|
||||
border: 1px solid #ddd;
|
||||
padding: 5px;
|
||||
margin-bottom: 5px;
|
||||
min-height: 100px;
|
||||
}
|
||||
|
||||
.index-display {
|
||||
font-size: 1.1em;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
button {
|
||||
margin: 0;
|
||||
padding: 8px 16px;
|
||||
background-color: #4CAF50;
|
||||
/* Green */
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #367c39;
|
||||
/* Darker green */
|
||||
}
|
||||
|
||||
.top-controls {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.top-controls button {
|
||||
margin-right: 20px;
|
||||
padding: 12px 24px;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.performance-table {
|
||||
width: auto;
|
||||
/* Adjust width to fit content */
|
||||
margin: 20px 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.performance-table th,
|
||||
.performance-table td {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
font-size: 0.9em;
|
||||
/* Reduce font size */
|
||||
}
|
||||
|
||||
.performance-table th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="top-controls">
|
||||
<h1>Training Run: {{ run }}</h1>
|
||||
<button onclick="goBack()">Go Back</button>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="column">
|
||||
{% for group, results in data.items() %}
|
||||
<h2>{{ group }}</h2>
|
||||
<table class="performance-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Metric</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for metric, value in results.items() %}
|
||||
<tr>
|
||||
<td>{{ metric }}</td>
|
||||
<td>{{ value }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="column">
|
||||
{% for split, data in generated_data.items() %}
|
||||
{% if data %}
|
||||
<div class="generated-text-container">
|
||||
<h2>Generated Text ({{ split }})</h2>
|
||||
<div id="{{ split }}-text" class="generated-text-display">
|
||||
<p><strong>Input:</strong> <span id="{{ split }}-input"></span></p>
|
||||
<p><strong>Generated:</strong> <span id="{{ split }}-generated"></span></p>
|
||||
<p><strong>Label:</strong> <span id="{{ split }}-label"></span></p>
|
||||
</div>
|
||||
<div class="generated-text-controls">
|
||||
<button onclick="prev('{{ split }}')">Prev</button>
|
||||
<input type="number" id="{{ split }}-index" value="1" min="1" max="{{ data|length }}"
|
||||
onchange="updateText('{{ split }}')">
|
||||
<span class="index-display">/ {{ data|length }}</span>
|
||||
<button onclick="next('{{ split }}')">Next</button>
|
||||
<button onclick="randomize('{{ split }}')">Random</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var generatedData = {{ generated_data | tojson }};
|
||||
|
||||
function updateText(split) {
|
||||
var index = parseInt(document.getElementById(split + '-index').value) - 1;
|
||||
var data = generatedData[split][index];
|
||||
document.getElementById(split + '-input').textContent = data.input;
|
||||
document.getElementById(split + '-generated').textContent = data.generated;
|
||||
document.getElementById(split + '-label').textContent = data.label;
|
||||
}
|
||||
|
||||
function next(split) {
|
||||
var indexInput = document.getElementById(split + '-index');
|
||||
var index = parseInt(indexInput.value);
|
||||
if (index < generatedData[split].length) {
|
||||
indexInput.value = index + 1;
|
||||
updateText(split);
|
||||
}
|
||||
}
|
||||
|
||||
function prev(split) {
|
||||
var indexInput = document.getElementById(split + '-index');
|
||||
var index = parseInt(indexInput.value);
|
||||
if (index > 1) {
|
||||
indexInput.value = index - 1;
|
||||
updateText(split);
|
||||
}
|
||||
}
|
||||
|
||||
function randomize(split) {
|
||||
var randomIndex = Math.floor(Math.random() * generatedData[split].length) + 1;
|
||||
document.getElementById(split + '-index').value = randomIndex;
|
||||
updateText(split);
|
||||
}
|
||||
|
||||
// Initialize text for each split
|
||||
{% for split, data in generated_data.items() %}
|
||||
{% if data %}
|
||||
updateText('{{ split }}');
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
function goBack() {
|
||||
window.history.back();
|
||||
}
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue