Commit
·
6733d53
1
Parent(s):
a77633e
find transformers install folder
Browse files
app.py
CHANGED
|
@@ -15,6 +15,8 @@ from typing import Dict, List, Optional
|
|
| 15 |
|
| 16 |
from flask import Flask, jsonify, render_template, request
|
| 17 |
|
|
|
|
|
|
|
| 18 |
|
| 19 |
class TransformersTimelineParser:
|
| 20 |
"""Parser for extracting model release dates from Transformers documentation."""
|
|
@@ -736,7 +738,11 @@ class TransformersTimelineParser:
|
|
| 736 |
|
| 737 |
# Initialize Flask app
|
| 738 |
app = Flask(__name__)
|
| 739 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 740 |
parser = TransformersTimelineParser(docs_dir)
|
| 741 |
|
| 742 |
|
|
@@ -2176,14 +2182,14 @@ def create_timeline_template():
|
|
| 2176 |
document.querySelectorAll('.timeline-label.expanded').forEach(otherLabel => {
|
| 2177 |
if (otherLabel !== label) {
|
| 2178 |
otherLabel.classList.remove('expanded');
|
| 2179 |
-
|
| 2180 |
// Restore compact content for other cards
|
| 2181 |
setTimeout(() => {
|
| 2182 |
otherLabel.innerHTML = `
|
| 2183 |
<div class="model-title">${otherLabel.dataset.modelName}</div>
|
| 2184 |
<div class="timeline-date">${otherLabel.dataset.modelDate}</div>
|
| 2185 |
`;
|
| 2186 |
-
|
| 2187 |
// Reset positioning after content change
|
| 2188 |
setTimeout(() => {
|
| 2189 |
otherLabel.style.top = '';
|
|
@@ -2203,16 +2209,16 @@ def create_timeline_template():
|
|
| 2203 |
const containerRect = label.parentElement.getBoundingClientRect();
|
| 2204 |
const currentTop = rect.top - containerRect.top;
|
| 2205 |
const currentBottom = containerRect.bottom - rect.bottom;
|
| 2206 |
-
|
| 2207 |
// Determine if this is above or below axis
|
| 2208 |
const isAboveAxis = positionClass.includes('above');
|
| 2209 |
-
|
| 2210 |
// Generate expanded content
|
| 2211 |
const storedTasks = label.dataset.tasks ? JSON.parse(label.dataset.tasks) : [];
|
| 2212 |
const formattedDescription = markdownToHtml(label.dataset.description);
|
| 2213 |
-
|
| 2214 |
// Format tasks for display with task-specific colors
|
| 2215 |
-
const tasksHtml = storedTasks && storedTasks.length > 0 ?
|
| 2216 |
`<div class="model-tasks">
|
| 2217 |
<div class="tasks-label">Supported Tasks:</div>
|
| 2218 |
<div class="tasks-list">
|
|
@@ -2221,9 +2227,9 @@ def create_timeline_template():
|
|
| 2221 |
return `<span class="task-badge" style="background-color: ${taskColor}">${task.replace(/-/g, ' ').replace(/\\b\\w/g, l => l.toUpperCase())}</span>`;
|
| 2222 |
}).join('')}
|
| 2223 |
</div>
|
| 2224 |
-
</div>` :
|
| 2225 |
'<div class="model-tasks"><div class="tasks-label">No tasks available</div></div>';
|
| 2226 |
-
|
| 2227 |
// Set expanded content
|
| 2228 |
label.innerHTML = `
|
| 2229 |
<div class="model-title">${label.dataset.modelName}</div>
|
|
@@ -2240,27 +2246,27 @@ def create_timeline_template():
|
|
| 2240 |
Learn More →
|
| 2241 |
</a>
|
| 2242 |
`;
|
| 2243 |
-
|
| 2244 |
// Add expanded class
|
| 2245 |
label.classList.add('expanded');
|
| 2246 |
-
|
| 2247 |
// Ensure this timeline item is on top
|
| 2248 |
item.style.zIndex = '10000';
|
| 2249 |
-
|
| 2250 |
// Set positioning to keep the correct edge fixed (using pre-expansion position)
|
| 2251 |
if (isAboveAxis) {
|
| 2252 |
// Keep top edge fixed - set top position
|
| 2253 |
label.style.bottom = 'auto';
|
| 2254 |
label.style.top = currentTop + 'px';
|
| 2255 |
} else {
|
| 2256 |
-
// Keep bottom edge fixed - set bottom position
|
| 2257 |
label.style.top = 'auto';
|
| 2258 |
label.style.bottom = currentBottom + 'px';
|
| 2259 |
}
|
| 2260 |
} else {
|
| 2261 |
// Contracting - remove expanded class first
|
| 2262 |
label.classList.remove('expanded');
|
| 2263 |
-
|
| 2264 |
// Wait for CSS transition to start, then restore compact content
|
| 2265 |
setTimeout(() => {
|
| 2266 |
// Restore compact content
|
|
@@ -2268,7 +2274,7 @@ def create_timeline_template():
|
|
| 2268 |
<div class="model-title">${label.dataset.modelName}</div>
|
| 2269 |
<div class="timeline-date">${label.dataset.modelDate}</div>
|
| 2270 |
`;
|
| 2271 |
-
|
| 2272 |
// Reset positioning after content change
|
| 2273 |
setTimeout(() => {
|
| 2274 |
label.style.top = '';
|
|
|
|
| 15 |
|
| 16 |
from flask import Flask, jsonify, render_template, request
|
| 17 |
|
| 18 |
+
import transformers
|
| 19 |
+
|
| 20 |
|
| 21 |
class TransformersTimelineParser:
|
| 22 |
"""Parser for extracting model release dates from Transformers documentation."""
|
|
|
|
| 738 |
|
| 739 |
# Initialize Flask app
|
| 740 |
app = Flask(__name__)
|
| 741 |
+
# Dynamically find the transformers installation directory
|
| 742 |
+
|
| 743 |
+
transformers_path = os.path.dirname(transformers.__file__)
|
| 744 |
+
docs_dir = os.path.join(transformers_path, "..", "docs", "source", "en", "model_doc")
|
| 745 |
+
docs_dir = os.path.abspath(docs_dir)
|
| 746 |
parser = TransformersTimelineParser(docs_dir)
|
| 747 |
|
| 748 |
|
|
|
|
| 2182 |
document.querySelectorAll('.timeline-label.expanded').forEach(otherLabel => {
|
| 2183 |
if (otherLabel !== label) {
|
| 2184 |
otherLabel.classList.remove('expanded');
|
| 2185 |
+
|
| 2186 |
// Restore compact content for other cards
|
| 2187 |
setTimeout(() => {
|
| 2188 |
otherLabel.innerHTML = `
|
| 2189 |
<div class="model-title">${otherLabel.dataset.modelName}</div>
|
| 2190 |
<div class="timeline-date">${otherLabel.dataset.modelDate}</div>
|
| 2191 |
`;
|
| 2192 |
+
|
| 2193 |
// Reset positioning after content change
|
| 2194 |
setTimeout(() => {
|
| 2195 |
otherLabel.style.top = '';
|
|
|
|
| 2209 |
const containerRect = label.parentElement.getBoundingClientRect();
|
| 2210 |
const currentTop = rect.top - containerRect.top;
|
| 2211 |
const currentBottom = containerRect.bottom - rect.bottom;
|
| 2212 |
+
|
| 2213 |
// Determine if this is above or below axis
|
| 2214 |
const isAboveAxis = positionClass.includes('above');
|
| 2215 |
+
|
| 2216 |
// Generate expanded content
|
| 2217 |
const storedTasks = label.dataset.tasks ? JSON.parse(label.dataset.tasks) : [];
|
| 2218 |
const formattedDescription = markdownToHtml(label.dataset.description);
|
| 2219 |
+
|
| 2220 |
// Format tasks for display with task-specific colors
|
| 2221 |
+
const tasksHtml = storedTasks && storedTasks.length > 0 ?
|
| 2222 |
`<div class="model-tasks">
|
| 2223 |
<div class="tasks-label">Supported Tasks:</div>
|
| 2224 |
<div class="tasks-list">
|
|
|
|
| 2227 |
return `<span class="task-badge" style="background-color: ${taskColor}">${task.replace(/-/g, ' ').replace(/\\b\\w/g, l => l.toUpperCase())}</span>`;
|
| 2228 |
}).join('')}
|
| 2229 |
</div>
|
| 2230 |
+
</div>` :
|
| 2231 |
'<div class="model-tasks"><div class="tasks-label">No tasks available</div></div>';
|
| 2232 |
+
|
| 2233 |
// Set expanded content
|
| 2234 |
label.innerHTML = `
|
| 2235 |
<div class="model-title">${label.dataset.modelName}</div>
|
|
|
|
| 2246 |
Learn More →
|
| 2247 |
</a>
|
| 2248 |
`;
|
| 2249 |
+
|
| 2250 |
// Add expanded class
|
| 2251 |
label.classList.add('expanded');
|
| 2252 |
+
|
| 2253 |
// Ensure this timeline item is on top
|
| 2254 |
item.style.zIndex = '10000';
|
| 2255 |
+
|
| 2256 |
// Set positioning to keep the correct edge fixed (using pre-expansion position)
|
| 2257 |
if (isAboveAxis) {
|
| 2258 |
// Keep top edge fixed - set top position
|
| 2259 |
label.style.bottom = 'auto';
|
| 2260 |
label.style.top = currentTop + 'px';
|
| 2261 |
} else {
|
| 2262 |
+
// Keep bottom edge fixed - set bottom position
|
| 2263 |
label.style.top = 'auto';
|
| 2264 |
label.style.bottom = currentBottom + 'px';
|
| 2265 |
}
|
| 2266 |
} else {
|
| 2267 |
// Contracting - remove expanded class first
|
| 2268 |
label.classList.remove('expanded');
|
| 2269 |
+
|
| 2270 |
// Wait for CSS transition to start, then restore compact content
|
| 2271 |
setTimeout(() => {
|
| 2272 |
// Restore compact content
|
|
|
|
| 2274 |
<div class="model-title">${label.dataset.modelName}</div>
|
| 2275 |
<div class="timeline-date">${label.dataset.modelDate}</div>
|
| 2276 |
`;
|
| 2277 |
+
|
| 2278 |
// Reset positioning after content change
|
| 2279 |
setTimeout(() => {
|
| 2280 |
label.style.top = '';
|