Download index.html from FYRGPT/FYRSTUDYAIGPT: direct link, hf CLI and curl.
- Browser
- Download file 68.8 kB
-
https://huggingface.co/FYRGPT/FYRSTUDYAIGPT/resolve/main/index.html
- Command line
-
hf download hf://FYRGPT/FYRSTUDYAIGPT/index.html
-
curl -L -o index.html https://huggingface.co/FYRGPT/FYRSTUDYAIGPT/resolve/main/index.html
68.8 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
>
<title>FYRStudyGPT</title>
<link
rel="stylesheet"
href="style.css"
>
</head>
<body>
<!-- =========================================
PICKER
========================================= -->
<div
id="pickerBackdrop"
class="picker-backdrop"
>
<div
class="picker-panel"
role="dialog"
aria-modal="true"
>
<div class="picker-header">
<div class="picker-header-text">
<div
id="pickerTitle"
class="picker-title"
>
Choose
</div>
<div
id="pickerSubtitle"
class="picker-subtitle"
></div>
</div>
<button
id="pickerClose"
class="picker-close"
type="button"
aria-label="Close"
>
×
</button>
</div>
<div
id="pickerOptions"
class="picker-options"
></div>
</div>
</div>
<!-- =========================================
APP
========================================= -->
<div class="app">
<!-- =========================================
SIDEBAR
========================================= -->
<aside class="sidebar">
<div class="brand-row">
<div class="brand-icon">
<div class="equalizer">
<span></span>
<span></span>
<span></span>
</div>
</div>
<div class="brand-text">
<div class="brand-name">
FYRStudyGPT
</div>
<div class="brand-tagline">
YOUR THINKING
<br>
PARTNER
</div>
</div>
<button
id="closeSidebar"
class="brand-close"
type="button"
aria-label="Close sidebar"
>
×
</button>
</div>
<button
id="newChat"
class="new-chat"
type="button"
>
<span class="new-plus">
+
</span>
New chat
<span class="key-badge">
N
</span>
</button>
<div class="sidebar-heading">
This space
</div>
<div class="session-card">
<div class="session-top">
<span class="session-spark">
✧
</span>
<span class="session-title">
Current session
</span>
<span class="session-dot"></span>
</div>
<div
id="sessionStatus"
class="session-sub"
>
Ready to begin
</div>
</div>
<button
id="subjectSidebarButton"
class="side-setting"
type="button"
>
<span class="side-setting-icon">
▤
</span>
<span class="side-setting-text">
<span class="side-setting-title">
Subject focus
</span>
<span
id="subjectSidebarValue"
class="side-setting-value"
>
Mathematics
</span>
</span>
<span class="side-chevron">
›
</span>
</button>
<button
id="modeSidebarButton"
class="side-setting"
type="button"
>
<span class="side-setting-icon">
♧
</span>
<span class="side-setting-text">
<span class="side-setting-title">
Study mode
</span>
<span
id="modeSidebarValue"
class="side-setting-value"
>
Ask Anything
</span>
</span>
<span class="side-chevron">
›
</span>
</button>
<button
id="modelSidebarButton"
class="side-setting"
type="button"
>
<span class="side-setting-icon">
◇
</span>
<span class="side-setting-text">
<span class="side-setting-title">
AI model
</span>
<span
id="modelSidebarValue"
class="side-setting-value"
>
Balanced · SmolLM2 360M
</span>
</span>
<span class="side-chevron">
›
</span>
</button>
<div class="sidebar-divider"></div>
<div class="sidebar-heading">
Recent
</div>
<div
id="chatList"
class="chat-list"
></div>
<div
id="recentEmpty"
class="recent-empty"
>
Your conversations will appear here
as you study.
</div>
<div class="sidebar-bottom">
<div class="learn-card">
<div class="learn-icon">
♢
</div>
<div class="learn-text">
<div class="learn-title">
Learn, don't just copy
</div>
<div class="learn-sub">
Understand the reasoning,
not only the answer.
</div>
</div>
</div>
<div class="appearance-row">
<div class="appearance-icon">
☼
</div>
<div class="appearance-info">
<div class="appearance-title">
Appearance
</div>
<div
id="themeLabel"
class="appearance-sub"
>
Light theme
</div>
</div>
<button
id="themeButton"
class="theme-button"
type="button"
>
☼
</button>
</div>
</div>
</aside>
<!-- =========================================
MAIN
========================================= -->
<main class="main">
<header class="topbar">
<button
id="menuButton"
class="menu-button"
type="button"
aria-label="Menu"
>
☰
</button>
<div class="breadcrumb">
<span>
Study space
</span>
<span class="breadcrumb-slash">
/
</span>
<button
id="breadcrumbSubject"
class="breadcrumb-subject"
type="button"
>
Math
</button>
</div>
<div class="top-actions">
<button
id="focusButton"
class="focus-button"
type="button"
>
<span class="focus-dot"></span>
<span>
Focus mode
</span>
</button>
<button
id="moonButton"
class="moon-button"
type="button"
>
☾
</button>
</div>
</header>
<div
id="workspace"
class="workspace"
>
<div class="content">
<!-- =========================================
HERO
========================================= -->
<section
id="hero"
class="hero"
>
<div class="hero-icon-wrap">
<span class="orbit-dot one"></span>
<span class="orbit-dot two"></span>
<div class="hero-icon">
♢
</div>
</div>
<div class="hero-kicker">
A CALMER WAY TO REVISE
</div>
<h1>
What would you like to understand?
</h1>
<p class="hero-subtitle">
Ask a question, test your thinking,
or make a plan for the next small step.
</p>
<div class="ai-intro">
<div class="ai-avatar">
◫
</div>
<div>
<div class="ai-name-row">
<span class="ai-name">
FYRStudyGPT
</span>
<span
id="introMode"
class="ai-mode-tag"
>
ASK MODE
</span>
</div>
<div class="ai-intro-text">
Hi, I'm FYRStudyGPT.
Ask me something normally and I'll
answer as naturally and clearly as I can.
</div>
<div class="ai-intro-text">
You can also switch to Explain Topic,
Quiz Me, Flashcards, Study Plan or
Check Answer when you need something
more structured.
</div>
</div>
</div>
</section>
<!-- =========================================
CHAT
========================================= -->
<section
id="chatThread"
class="chat-thread"
></section>
<!-- =========================================
PRE CHAT SETTINGS
========================================= -->
<section
id="preChatControls"
class="pre-chat-controls"
>
<div class="focus-heading">
Your focus
<span>
Optional context for FYRStudyGPT
</span>
</div>
<div class="focus-grid">
<button
id="subjectPickerButton"
class="focus-picker"
type="button"
>
<span class="focus-picker-icon">
▤
</span>
<span class="focus-picker-text">
<span class="focus-picker-label">
Subject
</span>
<span
id="subjectPickerValue"
class="focus-picker-value"
>
Mathematics
</span>
</span>
<span class="focus-picker-chevron">
›
</span>
</button>
<button
id="modePickerButton"
class="focus-picker"
type="button"
>
<span class="focus-picker-icon">
♧
</span>
<span class="focus-picker-text">
<span class="focus-picker-label">
Study mode
</span>
<span
id="modePickerValue"
class="focus-picker-value"
>
Ask Anything
</span>
</span>
<span class="focus-picker-chevron">
›
</span>
</button>
</div>
<div class="suggestion-heading">
<span>
Try starting with
</span>
<span>
ASK FYRSTUDYGPT
</span>
</div>
<div
id="suggestions"
class="suggestions"
></div>
</section>
<!-- =========================================
COMPOSER
========================================= -->
<section class="composer-area">
<div class="composer">
<textarea
id="messageInput"
rows="2"
placeholder="Ask FYRStudyGPT anything..."
></textarea>
<div class="composer-bottom">
<div class="composer-hint">
<span>
♧
</span>
Shift + Enter for a new line
</div>
<button
id="sendButton"
class="send-button"
type="button"
aria-label="Send"
>
◇
</button>
</div>
</div>
<div
id="loadingBox"
class="loading-box"
>
<div class="loading-top">
<span
id="loadingName"
class="loading-name"
>
Preparing FYRStudyGPT…
</span>
<span
id="loadingDetail"
class="loading-detail"
>
0%
</span>
</div>
<div class="loading-track">
<div
id="loadingFill"
class="loading-fill"
></div>
</div>
</div>
<div
id="errorBox"
class="error-box"
></div>
<div class="footer-note">
FYRStudyGPT can make mistakes.
Check important schoolwork with reliable sources.
</div>
</section>
</div>
</div>
</main>
</div>
<script>
/* =========================================
TRANSFORMERS.JS
========================================= */
let transformersPipeline =
null;
let transformersEnv =
null;
async function ensureTransformers() {
if (
transformersPipeline
) {
return;
}
const module =
await import(
"https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.8.1"
);
transformersPipeline =
module.pipeline;
transformersEnv =
module.env;
transformersEnv.allowLocalModels =
false;
transformersEnv.useBrowserCache =
true;
}
/* =========================================
MODELS
========================================= */
const MODELS = {
fast: {
id:
"onnx-community/SmolLM2-135M-Instruct-ONNX-MHA",
label:
"Fast",
short:
"SmolLM2 135M",
tokens:
220,
gpuDtype:
"q4f16",
cpuDtype:
"q4"
},
balanced: {
id:
"onnx-community/SmolLM2-360M-Instruct-ONNX",
label:
"Balanced",
short:
"SmolLM2 360M",
tokens:
300,
gpuDtype:
"q4f16",
cpuDtype:
"q4"
},
smart: {
id:
"onnx-community/Qwen2.5-0.5B-Instruct",
label:
"Smart",
short:
"Qwen2.5 0.5B",
tokens:
360,
gpuDtype:
"q4f16",
cpuDtype:
"q4"
}
};
/* =========================================
SUBJECTS
========================================= */
const SUBJECTS = [
{
value:
"Mathematics",
icon:
"➗",
description:
"Algebra, geometry and problem solving"
},
{
value:
"Science",
icon:
"⚗",
description:
"Biology, chemistry and physics"
},
{
value:
"English",
icon:
"✎",
description:
"Writing, comprehension and language"
},
{
value:
"Chinese",
icon:
"文",
description:
"Chinese language and comprehension"
},
{
value:
"History",
icon:
"⌛",
description:
"Events, sources and historical reasoning"
},
{
value:
"Geography",
icon:
"◎",
description:
"Places, environments and processes"
},
{
value:
"General",
icon:
"✦",
description:
"Questions outside a specific subject"
}
];
/* =========================================
STUDY MODES
========================================= */
const MODES = [
{
value:
"Ask Anything",
icon:
"💬",
description:
"Normal and natural conversation"
},
{
value:
"Explain Topic",
icon:
"💡",
description:
"Understand something step by step"
},
{
value:
"Quiz Me",
icon:
"✓",
description:
"Test yourself and get feedback"
},
{
value:
"Flashcards",
icon:
"▣",
description:
"Create interactive revision cards"
},
{
value:
"Study Plan",
icon:
"◷",
description:
"Build a realistic revision plan"
},
{
value:
"Check Answer",
icon:
"✎",
description:
"Get feedback on your own response"
}
];
/* =========================================
MODEL PICKER
========================================= */
const MODEL_OPTIONS = [
{
value:
"fast",
icon:
"⚡",
name:
"Fast",
description:
"SmolLM2 135M · quickest"
},
{
value:
"balanced",
icon:
"⚖",
name:
"Balanced",
description:
"SmolLM2 360M · default balance"
},
{
value:
"smart",
icon:
"✦",
name:
"Smart",
description:
"Qwen2.5 0.5B · strongest, slower"
}
];
/* =========================================
MODE DATA
========================================= */
const MODE_DATA = {
"Ask Anything": {
tag:
"ASK MODE",
placeholder:
"Ask FYRStudyGPT anything...",
suggestions: [
"Hi! What can you help me with?",
"Can you explain something I don't understand?",
"Help me with a question from school"
]
},
"Explain Topic": {
tag:
"TUTOR MODE",
placeholder:
"What would you like explained?",
suggestions: [
"Explain photosynthesis simply",
"Why does the quadratic formula work?",
"Explain this topic step by step"
]
},
"Quiz Me": {
tag:
"QUIZ MODE",
placeholder:
"What topic should I quiz you on?",
suggestions: [
"Quiz me on algebra",
"Test me on cells and respiration",
"Give me a short history quiz"
]
},
"Flashcards": {
tag:
"FLASHCARD MODE",
placeholder:
"What should I make flashcards about?",
suggestions: [
"Make photosynthesis flashcards",
"Create algebra revision cards",
"Make history key-date flashcards"
]
},
"Study Plan": {
tag:
"PLANNER MODE",
placeholder:
"What do you need to revise?",
suggestions: [
"Make me a 1 hour revision plan",
"Plan my maths and science revision",
"Help me revise three topics"
]
},
"Check Answer": {
tag:
"FEEDBACK MODE",
placeholder:
"Paste your question and answer...",
suggestions: [
"Check my maths working",
"Give feedback on my history response",
"Tell me how I can improve my answer"
]
}
};
/* =========================================
STORAGE
========================================= */
const previousProfile =
localStorage.getItem(
"studyai.lastProfile"
);
const STORAGE_PROFILE =
(
previousProfile
||
"default"
)
.trim()
.toLowerCase()
.replace(
/[^a-z0-9_-]+/g,
"_"
);
function chatStorageKey() {
return (
"studyai.chats."
+
STORAGE_PROFILE
);
}
function modelStorageKey() {
return (
"studyai.model."
+
STORAGE_PROFILE
);
}
/* =========================================
STATE
========================================= */
let chats =
[];
let currentChatId =
null;
let subject =
"Mathematics";
let mode =
"Ask Anything";
let selectedModelKey =
"balanced";
let generator =
null;
let loadingPromise =
null;
let modelRuntime =
"";
let history =
[];
let activeQuiz =
null;
let activePicker =
null;
/*
Used to prevent an old model load
from becoming active after switching.
*/
let modelLoadVersion =
0;
/* =========================================
ELEMENTS
========================================= */
const workspace =
document.getElementById(
"workspace"
);
const hero =
document.getElementById(
"hero"
);
const chatThread =
document.getElementById(
"chatThread"
);
const chatList =
document.getElementById(
"chatList"
);
const recentEmpty =
document.getElementById(
"recentEmpty"
);
const messageInput =
document.getElementById(
"messageInput"
);
const sendButton =
document.getElementById(
"sendButton"
);
const loadingBox =
document.getElementById(
"loadingBox"
);
const loadingName =
document.getElementById(
"loadingName"
);
const loadingDetail =
document.getElementById(
"loadingDetail"
);
const loadingFill =
document.getElementById(
"loadingFill"
);
const errorBox =
document.getElementById(
"errorBox"
);
const pickerBackdrop =
document.getElementById(
"pickerBackdrop"
);
const pickerTitle =
document.getElementById(
"pickerTitle"
);
const pickerSubtitle =
document.getElementById(
"pickerSubtitle"
);
const pickerOptions =
document.getElementById(
"pickerOptions"
);
/* =========================================
HELPERS
========================================= */
function makeId() {
return (
Date.now()
.toString(
36
)
+
Math.random()
.toString(
36
)
.slice(
2,
8
)
);
}
function getModel() {
return MODELS[
selectedModelKey
];
}
function subjectShortName() {
return (
subject
===
"Mathematics"
?
"Math"
:
subject
);
}
/* =========================================
AUTO SCROLL
========================================= */
function scrollToBottom(
smooth = true
) {
requestAnimationFrame(
() => {
workspace.scrollTo({
top:
workspace.scrollHeight,
behavior:
smooth
?
"smooth"
:
"auto"
});
}
);
}
/* =========================================
CHAT STORAGE
========================================= */
function loadChats() {
try {
const stored =
JSON.parse(
localStorage.getItem(
chatStorageKey()
)
||
"[]"
);
chats =
Array.isArray(
stored
)
?
stored
:
[];
}
catch {
chats =
[];
}
renderChatList();
}
function saveChats() {
chats.sort(
(a, b) =>
b.updated
-
a.updated
);
chats =
chats.slice(
0,
40
);
localStorage.setItem(
chatStorageKey(),
JSON.stringify(
chats
)
);
renderChatList();
}
/* =========================================
CHAT LIST
========================================= */
function renderChatList() {
chatList.innerHTML =
"";
recentEmpty.style.display =
chats.length
?
"none"
:
"block";
chats
.slice(
0,
15
)
.forEach(
saved => {
const button =
document.createElement(
"button"
);
button.type =
"button";
button.className =
"saved-chat"
+
(
saved.id
===
currentChatId
?
" active"
:
""
);
button.textContent =
saved.title
||
"New chat";
button.addEventListener(
"click",
() => {
openChat(
saved.id
);
}
);
chatList.appendChild(
button
);
}
);
}
/* =========================================
CHAT CREATION
========================================= */
function getCurrentChat() {
return chats.find(
chat =>
chat.id
===
currentChatId
);
}
function createChat(
firstMessage
) {
const saved = {
id:
makeId(),
title:
firstMessage
.slice(
0,
40
),
subject:
subject,
mode:
mode,
model:
selectedModelKey,
updated:
Date.now(),
messages:
[]
};
chats.unshift(
saved
);
currentChatId =
saved.id;
return saved;
}
function getOrCreateChat(
firstMessage
) {
return (
getCurrentChat()
||
createChat(
firstMessage
)
);
}
/* =========================================
NEW CHAT
========================================= */
function newChat() {
currentChatId =
null;
history =
[];
activeQuiz =
null;
/*
Ask Anything is the default
for every new conversation.
*/
mode =
"Ask Anything";
document.body
.classList
.remove(
"chat-started"
);
hero.style.display =
"block";
chatThread
.classList
.remove(
"active"
);
chatThread.innerHTML =
"";
document
.getElementById(
"sessionStatus"
)
.textContent =
generator
?
"Ready · "
+
getModel().label
:
"Ready to begin";
updateAllUI();
renderChatList();
workspace.scrollTo({
top:
0,
behavior:
"smooth"
});
}
document
.getElementById(
"newChat"
)
.addEventListener(
"click",
newChat
);
/* =========================================
OPEN CHAT
========================================= */
function openChat(
id
) {
const saved =
chats.find(
chat =>
chat.id
===
id
);
if (
!saved
) {
return;
}
currentChatId =
saved.id;
subject =
saved.subject
||
"Mathematics";
mode =
saved.mode
||
"Ask Anything";
history =
[];
activeQuiz =
null;
hero.style.display =
"none";
chatThread
.classList
.add(
"active"
);
document.body
.classList
.add(
"chat-started"
);
chatThread.innerHTML =
"";
const messages =
Array.isArray(
saved.messages
)
?
saved.messages
:
[];
messages.forEach(
item => {
if (
item.role
===
"user"
) {
addMessage(
item.content,
"user",
false
);
}
else {
const bubble =
addMessage(
"",
"assistant",
false
);
renderAIResponse(
bubble,
item.content,
item.mode
||
saved.mode
||
"Ask Anything",
false
);
}
history.push({
role:
item.role
===
"assistant"
?
"assistant"
:
"user",
content:
item.content
});
}
);
history =
history.slice(
-8
);
updateAllUI();
renderChatList();
setTimeout(
() => {
scrollToBottom(
false
);
},
50
);
}
/* =========================================
PICKER
========================================= */
function openPicker(
type
) {
activePicker =
type;
pickerOptions.innerHTML =
"";
let items =
[];
let current =
"";
if (
type
===
"subject"
) {
pickerTitle.textContent =
"Choose a subject";
pickerSubtitle.textContent =
"This gives FYRStudyGPT useful context when your question is about school.";
items =
SUBJECTS;
current =
subject;
}
else if (
type
===
"mode"
) {
pickerTitle.textContent =
"Choose a study mode";
pickerSubtitle.textContent =
"Choose how you want FYRStudyGPT to respond.";
items =
MODES;
current =
mode;
}
else {
pickerTitle.textContent =
"Choose your AI";
pickerSubtitle.textContent =
"Balanced is the default. Smart may be more capable but takes longer to load.";
items =
MODEL_OPTIONS;
current =
selectedModelKey;
}
items.forEach(
item => {
const value =
item.value;
const button =
document.createElement(
"button"
);
button.type =
"button";
button.className =
"picker-option"
+
(
value
===
current
?
" selected"
:
""
);
const icon =
document.createElement(
"span"
);
icon.className =
"picker-option-icon";
icon.textContent =
item.icon;
const main =
document.createElement(
"span"
);
main.className =
"picker-option-main";
const title =
document.createElement(
"span"
);
title.className =
"picker-option-name";
title.textContent =
item.name
||
item.value;
const description =
document.createElement(
"span"
);
description.className =
"picker-option-description";
description.textContent =
item.description;
main.append(
title,
description
);
const check =
document.createElement(
"span"
);
check.className =
"picker-check";
check.textContent =
value
===
current
?
"✓"
:
"";
button.append(
icon,
main,
check
);
button.addEventListener(
"click",
async () => {
const pickerType =
activePicker;
closePicker();
if (
pickerType
===
"subject"
) {
subject =
value;
updateAllUI();
}
else if (
pickerType
===
"mode"
) {
mode =
value;
activeQuiz =
null;
updateAllUI();
}
else {
await chooseModel(
value
);
}
}
);
pickerOptions.appendChild(
button
);
}
);
pickerBackdrop
.classList
.add(
"visible"
);
}
function closePicker() {
pickerBackdrop
.classList
.remove(
"visible"
);
activePicker =
null;
}
document
.getElementById(
"pickerClose"
)
.addEventListener(
"click",
closePicker
);
pickerBackdrop.addEventListener(
"click",
event => {
if (
event.target
===
pickerBackdrop
) {
closePicker();
}
}
);
document
.getElementById(
"subjectPickerButton"
)
.addEventListener(
"click",
() => openPicker(
"subject"
)
);
document
.getElementById(
"modePickerButton"
)
.addEventListener(
"click",
() => openPicker(
"mode"
)
);
document
.getElementById(
"subjectSidebarButton"
)
.addEventListener(
"click",
() => openPicker(
"subject"
)
);
document
.getElementById(
"modeSidebarButton"
)
.addEventListener(
"click",
() => openPicker(
"mode"
)
);
document
.getElementById(
"modelSidebarButton"
)
.addEventListener(
"click",
() => openPicker(
"model"
)
);
document
.getElementById(
"breadcrumbSubject"
)
.addEventListener(
"click",
() => openPicker(
"subject"
)
);
/* =========================================
UI UPDATE
========================================= */
function updateAllUI() {
document
.getElementById(
"breadcrumbSubject"
)
.textContent =
subjectShortName();
document
.getElementById(
"subjectSidebarValue"
)
.textContent =
subject;
document
.getElementById(
"modeSidebarValue"
)
.textContent =
mode;
document
.getElementById(
"subjectPickerValue"
)
.textContent =
subject;
document
.getElementById(
"modePickerValue"
)
.textContent =
mode;
document
.getElementById(
"introMode"
)
.textContent =
MODE_DATA[
mode
].tag;
messageInput.placeholder =
MODE_DATA[
mode
]
.placeholder;
const model =
getModel();
document
.getElementById(
"modelSidebarValue"
)
.textContent =
model.label
+
" · "
+
model.short;
renderSuggestions();
}
/* =========================================
SUGGESTIONS
========================================= */
function renderSuggestions() {
const container =
document.getElementById(
"suggestions"
);
container.innerHTML =
"";
MODE_DATA[
mode
]
.suggestions
.forEach(
text => {
const button =
document.createElement(
"button"
);
button.type =
"button";
button.className =
"suggestion";
const label =
document.createElement(
"span"
);
label.textContent =
text;
const arrow =
document.createElement(
"span"
);
arrow.className =
"suggestion-arrow";
arrow.textContent =
"↗";
button.append(
label,
arrow
);
button.addEventListener(
"click",
() => {
messageInput.value =
text;
resizeInput();
updateSendState();
messageInput.focus();
}
);
container.appendChild(
button
);
}
);
}
/* =========================================
MODEL MANAGEMENT
========================================= */
async function releaseModel() {
modelLoadVersion++;
if (
generator
&&
typeof
generator.dispose
===
"function"
) {
try {
await generator.dispose();
}
catch (
error
) {
console.warn(
error
);
}
}
generator =
null;
loadingPromise =
null;
modelRuntime =
"";
}
async function chooseModel(
key
) {
if (
!MODELS[
key
]
) {
return;
}
if (
key
===
selectedModelKey
&&
generator
) {
return;
}
await releaseModel();
selectedModelKey =
key;
localStorage.setItem(
modelStorageKey(),
key
);
updateAllUI();
document
.getElementById(
"sessionStatus"
)
.textContent =
"Preparing "
+
getModel().label
+
" AI";
loadAI()
.catch(
error => {
console.warn(
"AI loading failed:",
error
);
}
);
}
/* =========================================
LOADING PROGRESS
========================================= */
function updateProgress(
percent
) {
const value =
Math.max(
0,
Math.min(
100,
Math.round(
percent
)
)
);
loadingFill.style.width =
Math.max(
3,
value
)
+
"%";
loadingDetail.textContent =
value
+
"%";
}
/* =========================================
PIPELINE ATTEMPT
========================================= */
async function createPipeline(
modelKey,
version
) {
await ensureTransformers();
const model =
MODELS[
modelKey
];
const attempts =
[];
if (
"gpu"
in
navigator
) {
attempts.push({
name:
"GPU · "
+
model.gpuDtype,
options: {
device:
"webgpu",
dtype:
model.gpuDtype
}
});
}
attempts.push({
name:
"CPU · "
+
model.cpuDtype,
options: {
dtype:
model.cpuDtype
}
});
let lastError =
null;
for (
const attempt
of
attempts
) {
try {
updateProgress(
0
);
loadingName.textContent =
"Loading "
+
model.label
+
" AI";
loadingDetail.textContent =
attempt.name;
let highest =
0;
const pipe =
await transformersPipeline(
"text-generation",
model.id,
{
...attempt.options,
progress_callback:
progress => {
if (
progress.status
===
"progress"
&&
typeof
progress.progress
===
"number"
) {
highest =
Math.max(
highest,
progress.progress
);
updateProgress(
highest
);
}
}
}
);
/*
User switched models while
this model was downloading.
*/
if (
version
!==
modelLoadVersion
) {
if (
typeof
pipe.dispose
===
"function"
) {
try {
await pipe.dispose();
}
catch {
}
}
throw new Error(
"Model loading was cancelled."
);
}
return {
pipe:
pipe,
runtime:
attempt.name
};
}
catch (
error
) {
lastError =
error;
console.warn(
model.label
+
" failed using "
+
attempt.name,
error
);
}
}
throw (
lastError
||
new Error(
"Model could not be loaded."
)
);
}
/* =========================================
LOAD AI
========================================= */
async function loadAI() {
if (
generator
) {
return generator;
}
if (
loadingPromise
) {
return loadingPromise;
}
const requestedModelKey =
selectedModelKey;
const version =
modelLoadVersion;
loadingPromise =
(
async () => {
loadingBox
.classList
.add(
"visible"
);
errorBox.textContent =
"";
loadingName.textContent =
"Preparing FYRStudyGPT…";
updateProgress(
0
);
try {
const result =
await createPipeline(
requestedModelKey,
version
);
if (
version
!==
modelLoadVersion
) {
throw new Error(
"Model loading was cancelled."
);
}
generator =
result.pipe;
modelRuntime =
result.runtime;
}
catch (
firstError
) {
/*
Balanced / Smart failed completely.
Fall back to Fast so the app remains usable.
*/
if (
requestedModelKey
!==
"fast"
&&
version
===
modelLoadVersion
) {
loadingName.textContent =
"Falling back to Fast AI…";
const fallback =
await createPipeline(
"fast",
version
);
generator =
fallback.pipe;
modelRuntime =
fallback.runtime;
selectedModelKey =
"fast";
updateAllUI();
errorBox.textContent =
MODELS[
requestedModelKey
].label
+
" could not load on this device, so FYRStudyGPT switched to Fast.";
}
else {
throw firstError;
}
}
updateProgress(
100
);
loadingName.textContent =
"FYRStudyGPT is ready";
loadingDetail.textContent =
modelRuntime;
document
.getElementById(
"sessionStatus"
)
.textContent =
"Ready · "
+
getModel().label;
setTimeout(
() => {
loadingBox
.classList
.remove(
"visible"
);
},
700
);
return generator;
}
)();
try {
return await loadingPromise;
}
catch (
error
) {
generator =
null;
loadingName.textContent =
"FYRStudyGPT couldn't start";
loadingDetail.textContent =
"Load failed";
errorBox.textContent =
error?.message
||
String(
error
);
document
.getElementById(
"sessionStatus"
)
.textContent =
"AI load failed";
throw error;
}
finally {
loadingPromise =
null;
}
}
/* =========================================
SYSTEM PROMPT
========================================= */
function systemPrompt() {
return `You are FYRStudyGPT, a friendly and helpful study assistant for secondary-school students.
Respond naturally to the user.
If the user says hello or makes casual conversation, respond naturally like a normal assistant.
If the user asks a simple question, answer it directly.
If they ask for an explanation, explain it clearly.
Do not automatically turn every answer into a numbered list.
Use numbered steps only when steps genuinely make the answer easier to understand.
Do not repeat the user's question unnecessarily.
Do not turn casual conversation into a lesson unless the user asks.
For school questions, explain useful reasoning instead of only giving an answer.
Be concise for simple questions and more detailed when the question needs explanation.
Current subject context: ${subject}. Only use this subject context when it is relevant.
Do not invent facts. If you are uncertain, clearly say so.`;
}
/* =========================================
SPECIAL MODE PROMPTS
========================================= */
function createPrompt(
text
) {
/*
Ask Anything stays natural.
Do not wrap "hi" or a normal question
inside a giant school prompt.
*/
if (
mode
===
"Ask Anything"
) {
return text;
}
if (
mode
===
"Explain Topic"
) {
return `Explain the following clearly for a secondary-school student.
Subject: ${subject}
Topic or question:
${text}
Start with a clear explanation in normal paragraphs.
Use steps or bullet points only if they genuinely help.
Give an example when useful.
Finish with a short recap.`;
}
if (
mode
===
"Quiz Me"
) {
if (
activeQuiz
) {
const previousQuiz =
activeQuiz;
activeQuiz =
null;
return `You previously gave the student this quiz:
${previousQuiz}
Their answers are:
${text}
Mark the answers clearly.
Explain mistakes briefly and give the correct answer when needed.
Finish with the score and what the student should revise.`;
}
return `Create a 5-question quiz.
Subject: ${subject}
Topic:
${text}
Do not reveal the answers yet.
Number the five questions and ask the student to reply with their answers.`;
}
if (
mode
===
"Flashcards"
) {
return `Create exactly 8 useful revision flashcards.
Subject: ${subject}
Topic:
${text}
Use exactly this structure:
Q: question
A: answer
Do not add an introduction or conclusion.`;
}
if (
mode
===
"Study Plan"
) {
return `Create a realistic 1-hour study plan.
Subject: ${subject}
The student wants to revise:
${text}
Include sensible timed blocks, active recall, practice, one short break and a final recap.`;
}
if (
mode
===
"Check Answer"
) {
return `Give constructive feedback on this student's answer.
Subject: ${subject}
Question and/or answer:
${text}
Explain:
- what is correct
- what is missing or incorrect
- how to improve it
- a stronger answer or method when useful
Be clear and encouraging without pretending an incorrect answer is correct.`;
}
return text;
}
/* =========================================
OUTPUT
========================================= */
function extractOutput(
result
) {
const generated =
result?.[0]
?.generated_text;
if (
Array.isArray(
generated
)
) {
const last =
generated[
generated.length
-
1
];
if (
typeof
last?.content
===
"string"
) {
return last.content.trim();
}
}
if (
typeof
generated
===
"string"
) {
return generated.trim();
}
return "";
}
/* =========================================
GENERATE ANSWER
========================================= */
async function generateAnswer(
prompt
) {
const messages = [
{
role:
"system",
content:
systemPrompt()
},
...history.slice(
-6
),
{
role:
"user",
content:
prompt
}
];
/*
Deterministic generation gives
more consistent study answers.
*/
const options = {
max_new_tokens:
getModel().tokens,
do_sample:
false,
repetition_penalty:
1.05
};
/*
First use the model's chat template.
*/
try {
const result =
await generator(
messages,
options
);
const answer =
extractOutput(
result
);
if (
answer
) {
return answer;
}
}
catch (
error
) {
console.warn(
"Chat-template generation failed. Trying text fallback.",
error
);
}
/*
Plain-text fallback for models /
browsers that reject message arrays.
*/
const historyText =
history
.slice(
-4
)
.map(
item => {
return (
(
item.role
===
"assistant"
?
"FYRStudyGPT"
:
"User"
)
+
": "
+
item.content
);
}
)
.join(
"\n\n"
);
const fallbackPrompt =
systemPrompt()
+
"\n\n"
+
historyText
+
(
historyText
?
"\n\n"
:
""
)
+
"User: "
+
prompt
+
"\n\nFYRStudyGPT:";
const result =
await generator(
fallbackPrompt,
{
...options,
return_full_text:
false
}
);
const answer =
extractOutput(
result
);
return (
answer
||
"I couldn't generate a useful response. Try rewording your question."
);
}
/* =========================================
MESSAGE UI
========================================= */
function addMessage(
text,
role,
autoScroll = true
) {
hero.style.display =
"none";
chatThread
.classList
.add(
"active"
);
const row =
document.createElement(
"div"
);
row.className =
"message "
+
role;
const bubble =
document.createElement(
"div"
);
bubble.className =
"message-bubble";
bubble.textContent =
text;
row.appendChild(
bubble
);
chatThread.appendChild(
row
);
if (
autoScroll
) {
scrollToBottom();
}
return bubble;
}
/* =========================================
FLASHCARDS
========================================= */
function parseFlashcards(
text
) {
const lines =
text.split(
"\n"
);
const cards =
[];
let question =
null;
for (
const rawLine
of
lines
) {
const line =
rawLine.trim();
if (
/^Q\s*:/i
.test(
line
)
) {
question =
line
.replace(
/^Q\s*:/i,
""
)
.trim();
}
else if (
question
&&
/^A\s*:/i
.test(
line
)
) {
cards.push({
question:
question,
answer:
line
.replace(
/^A\s*:/i,
""
)
.trim()
});
question =
null;
}
}
return cards;
}
/* =========================================
RENDER AI RESPONSE
========================================= */
function renderAIResponse(
bubble,
text,
responseMode,
autoScroll = true
) {
if (
responseMode
===
"Flashcards"
) {
const cards =
parseFlashcards(
text
);
if (
cards.length
>=
2
) {
bubble.className =
"flashcards";
bubble.textContent =
"";
cards.forEach(
data => {
const card =
document.createElement(
"button"
);
card.type =
"button";
card.className =
"flashcard";
const question =
document.createElement(
"div"
);
question.className =
"flash-q";
question.textContent =
data.question;
const answer =
document.createElement(
"div"
);
answer.className =
"flash-a";
answer.textContent =
data.answer;
const hint =
document.createElement(
"div"
);
hint.className =
"flash-hint";
hint.textContent =
"Tap to reveal";
card.append(
question,
answer,
hint
);
card.addEventListener(
"click",
() => {
card
.classList
.toggle(
"open"
);
hint.textContent =
card
.classList
.contains(
"open"
)
?
"Tap to hide"
:
"Tap to reveal";
}
);
bubble.appendChild(
card
);
}
);
if (
autoScroll
) {
scrollToBottom();
}
return;
}
}
bubble.textContent =
text;
if (
responseMode
===
"Explain Topic"
) {
bubble
.classList
.add(
"explain"
);
}
else if (
responseMode
===
"Quiz Me"
) {
bubble
.classList
.add(
"quiz"
);
}
else if (
responseMode
===
"Study Plan"
) {
bubble
.classList
.add(
"study-plan"
);
}
else if (
responseMode
===
"Check Answer"
) {
bubble
.classList
.add(
"check-answer"
);
}
if (
autoScroll
) {
scrollToBottom();
}
}
/* =========================================
SEND
========================================= */
async function sendMessage() {
const text =
messageInput.value.trim();
if (
!text
||
sendButton.disabled
) {
return;
}
const responseMode =
mode;
const quizWasActive =
Boolean(
activeQuiz
);
const saved =
getOrCreateChat(
text
);
saved.subject =
subject;
saved.mode =
mode;
saved.model =
selectedModelKey;
saved.updated =
Date.now();
saved.messages.push({
role:
"user",
content:
text,
mode:
responseMode
});
saveChats();
/*
Hide subject/mode/suggestions
after the first message.
*/
document.body
.classList
.add(
"chat-started"
);
addMessage(
text,
"user"
);
messageInput.value =
"";
resizeInput();
updateSendState();
sendButton.disabled =
true;
document
.getElementById(
"sessionStatus"
)
.textContent =
generator
?
"Thinking…"
:
"Starting AI…";
scrollToBottom();
const responseBubble =
addMessage(
generator
?
"Thinking…"
:
"Preparing FYRStudyGPT…",
"assistant"
);
try {
await loadAI();
responseBubble.textContent =
"Thinking…";
scrollToBottom();
const prompt =
createPrompt(
text
);
const answer =
await generateAnswer(
prompt
);
renderAIResponse(
responseBubble,
answer,
responseMode
);
if (
responseMode
===
"Quiz Me"
&&
!quizWasActive
) {
activeQuiz =
answer;
}
/*
Store natural conversation for
future turns.
Ask Anything stores the original
user text rather than a big wrapper.
*/
history.push(
{
role:
"user",
content:
responseMode
===
"Ask Anything"
?
text
:
prompt
},
{
role:
"assistant",
content:
answer
}
);
history =
history.slice(
-8
);
saved.messages.push({
role:
"assistant",
content:
answer,
mode:
responseMode
});
saved.model =
selectedModelKey;
saved.updated =
Date.now();
saveChats();
document
.getElementById(
"sessionStatus"
)
.textContent =
"Ready · "
+
getModel().label;
scrollToBottom();
}
catch (
error
) {
console.error(
error
);
responseBubble.textContent =
"I couldn't start the AI. Try choosing Fast, or reload the page.";
scrollToBottom();
}
finally {
sendButton.disabled =
false;
updateSendState();
messageInput.focus();
}
}
/* =========================================
TEXT AREA
========================================= */
function resizeInput() {
messageInput.style.height =
"auto";
messageInput.style.height =
Math.min(
messageInput.scrollHeight,
160
)
+
"px";
}
function updateSendState() {
sendButton
.classList
.toggle(
"ready",
messageInput.value
.trim()
.length
>
0
);
}
messageInput.addEventListener(
"input",
() => {
resizeInput();
updateSendState();
}
);
messageInput.addEventListener(
"keydown",
event => {
if (
event.key
===
"Enter"
&&
!event.shiftKey
) {
event.preventDefault();
sendMessage();
}
}
);
sendButton.addEventListener(
"click",
sendMessage
);
/* =========================================
THEME
========================================= */
function setTheme(
dark
) {
document.body
.classList
.toggle(
"dark",
dark
);
document
.getElementById(
"themeLabel"
)
.textContent =
dark
?
"Dark theme"
:
"Light theme";
document
.getElementById(
"themeButton"
)
.textContent =
dark
?
"☾"
:
"☼";
localStorage.setItem(
"studyai.dark",
dark
?
"1"
:
"0"
);
}
function toggleTheme() {
setTheme(
!document.body
.classList
.contains(
"dark"
)
);
}
document
.getElementById(
"themeButton"
)
.addEventListener(
"click",
toggleTheme
);
document
.getElementById(
"moonButton"
)
.addEventListener(
"click",
toggleTheme
);
/* =========================================
SIDEBAR / FOCUS
========================================= */
document
.getElementById(
"focusButton"
)
.addEventListener(
"click",
() => {
document.body
.classList
.toggle(
"focus-mode"
);
}
);
document
.getElementById(
"menuButton"
)
.addEventListener(
"click",
() => {
if (
window.innerWidth
<=
720
) {
document.body
.classList
.toggle(
"sidebar-open"
);
}
else {
document.body
.classList
.toggle(
"focus-mode"
);
}
}
);
document
.getElementById(
"closeSidebar"
)
.addEventListener(
"click",
() => {
if (
window.innerWidth
<=
720
) {
document.body
.classList
.remove(
"sidebar-open"
);
}
else {
document.body
.classList
.add(
"focus-mode"
);
}
}
);
/* =========================================
KEYBOARD
========================================= */
document.addEventListener(
"keydown",
event => {
const tag =
event.target
?.tagName
?.toLowerCase()
||
"";
if (
event.key
.toLowerCase()
===
"n"
&&
tag
!==
"input"
&&
tag
!==
"textarea"
&&
!pickerBackdrop
.classList
.contains(
"visible"
)
) {
newChat();
}
if (
event.key
===
"Escape"
) {
closePicker();
document.body
.classList
.remove(
"sidebar-open"
);
}
}
);
/* =========================================
STARTUP
========================================= */
const savedModel =
localStorage.getItem(
modelStorageKey()
);
/*
Balanced is the default for new users.
If somebody manually selected a model before,
their selection is remembered.
*/
if (
savedModel
&&
MODELS[
savedModel
]
) {
selectedModelKey =
savedModel;
}
const savedDark =
localStorage.getItem(
"studyai.dark"
)
===
"1";
setTheme(
savedDark
);
loadChats();
updateAllUI();
newChat();
updateSendState();
if (
navigator.storage
&&
navigator.storage.persist
) {
navigator.storage
.persist()
.catch(
() => {}
);
}
/*
Give the webpage time to appear first,
then start loading the AI.
*/
setTimeout(
() => {
loadAI()
.catch(
error => {
console.warn(
"Background AI loading failed:",
error
);
}
);
},
900
);
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
>
<title>FYRStudyGPT</title>
<link
rel="stylesheet"
href="style.css"
>
</head>
<body>
<!-- =========================================
PICKER
========================================= -->
<div
id="pickerBackdrop"
class="picker-backdrop"
>
<div
class="picker-panel"
role="dialog"
aria-modal="true"
>
<div class="picker-header">
<div class="picker-header-text">
<div
id="pickerTitle"
class="picker-title"
>
Choose
</div>
<div
id="pickerSubtitle"
class="picker-subtitle"
></div>
</div>
<button
id="pickerClose"
class="picker-close"
type="button"
aria-label="Close"
>
×
</button>
</div>
<div
id="pickerOptions"
class="picker-options"
></div>
</div>
</div>
<!-- =========================================
APP
========================================= -->
<div class="app">
<!-- =========================================
SIDEBAR
========================================= -->
<aside class="sidebar">
<div class="brand-row">
<div class="brand-icon">