Front page
AI study helper
Flashcards and quizzes on demand
A study app built at a hackathon. Users sign up, then generate flashcards and quizzes through the Hugging Face AI API.
It includes user settings and a MySQL database.
- PHP, MySQL, JavaScript, Hugging Face API
- Digital School Hackathon
Asking the model for flashcards
The student’s summary goes to the model with instructions to answer in JSON between <json> tags; the code pulls that block out and decodes it into cards.
$messages = [ [ 'role' => 'system', 'content' => 'You are a helpful assistant for students. Generate flashcards in JSON format for academic topics. Output ONLY valid JSON in this format: [{"question":"...","answer":"..."}, ...]. Surround your JSON with <json>...</json> tags.' ], [ 'role' => 'user', 'content' => "Create a set of flashcards (question/term and answer/explanation) to help me study the following topic:\n\n" . $summary ]]; $response = callHuggingFaceAPI($messages, $user_id, $db, 1000); // Extract JSON between <json>...</json>if (preg_match('/<json>(.*?)<\/json>/is', $response, $m)) { $json_str = trim($m[1]);} else { $json_str = $response;} $cards = json_decode($json_str, true);
Calling the Hugging Face router
Requests go to the Hugging Face router’s chat-completions endpoint with the model and token each user saves in their settings.
// Hugging Face Router API endpoint - uses OpenAI-compatible chat completions format$endpoint = "https://router.huggingface.co/v1/chat/completions"; // Prepare payload in OpenAI-compatible format// Router will automatically select the best provider for this model$payload = [ 'model' => $model, 'messages' => $messages, 'max_tokens' => $max_tokens, 'temperature' => 0.7, 'stream' => false]; $ch = curl_init($endpoint);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Authorization: Bearer ' . $token]);