Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_API_URL=http://localhost:5000
REACT_APP_HUGGINGFACE_TOKEN=api_token
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Frontend Environment Variables
REACT_APP_API_URL=http://localhost:5000
REACT_APP_HUGGINGFACE_TOKEN=your_huggingface_token_here
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
123 changes: 123 additions & 0 deletions AI_INTEGRATION_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# AI Question Generator Integration

This project now includes **LLaMA-2 powered question generation** that can create contextual questions based on any topic and description.

## 🚀 Features

- **AI-Powered**: Uses Meta's LLaMA-2 model via Hugging Face API
- **Topic-Based**: Generate questions for any subject or topic
- **Multiple Types**: Multiple choice, True/False, and Short answer questions
- **Difficulty Levels**: Easy, Medium, and Hard difficulty options
- **Smart Fallback**: Provides backup questions if AI service is unavailable
- **Seamless Integration**: Works directly within the admin dashboard

## 🛠️ Setup Instructions

### 1. Get Hugging Face API Token
1. Go to [Hugging Face](https://huggingface.co/settings/tokens)
2. Create a new token with "Read" permissions
3. Copy your token (starts with `hf_`)

### 2. Configure Environment
The token is already configured in:
- `python-backend/.env`
- `backend/.env`

Current token: `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`

### 3. Start the AI Backend
```bash
# Option 1: Use the complete fix script
COMPLETE_FIX.bat
# Choose option 4: Start AI Backend

# Option 2: Manual start
cd python-backend
python app.py
```

### 4. Use AI Generation in React App
1. Start your React app: `npm start`
2. Login as admin (admin/admin123)
3. Click "AI Generator" button in admin dashboard
4. Enter topic and description
5. Configure question settings
6. Generate questions with AI!

## 📋 API Endpoints

The Python backend provides these endpoints:

- `POST /api/generate-questions` - Generate questions with LLaMA-2
- `GET /api/health` - Health check
- `POST /api/test-llama` - Test LLaMA connection

## 🎯 How to Use

### In the Admin Dashboard:
1. Click the **"AI Generator"** button (purple button with brain icon)
2. Fill in the form:
- **Topic**: e.g., "Machine Learning", "World War II", "Calculus"
- **Description**: Optional context or specific focus areas
- **Number of Questions**: 1-10 questions
- **Difficulty**: Easy, Medium, or Hard
- **Question Type**: Multiple Choice, True/False, or Short Answer
3. Click **"Generate Questions with AI"**
4. Questions are automatically created and added to your exam library

### Example Topics:
- **Science**: "Photosynthesis", "Quantum Physics", "DNA Structure"
- **History**: "American Revolution", "Ancient Rome", "Cold War"
- **Math**: "Algebra", "Calculus", "Statistics"
- **Technology**: "Machine Learning", "Web Development", "Cybersecurity"
- **Literature**: "Shakespeare", "Poetry Analysis", "Novel Structure"

## 🔧 Technical Details

### Architecture:
- **Frontend**: React component (`AIQuestionGenerator.js`)
- **Backend**: Python Flask API (`python-backend/app.py`)
- **AI Service**: LLaMA-2 via Hugging Face Inference API
- **Question Parser**: Smart text parsing to extract structured questions

### Question Format:
The AI generates questions in this structure:
```json
{
"id": 1,
"question": "What is the main concept of machine learning?",
"type": "multiple_choice",
"options": ["Supervised learning", "Data analysis", "Pattern recognition", "All of the above"],
"correct_answer": "D",
"explanation": "Machine learning encompasses all these concepts...",
"points": 1
}
```

## 🚨 Troubleshooting

### "Endpoint not found" error:
- Make sure Python backend is running on port 5000
- Check that `python-backend/app.py` is started
- Verify the Hugging Face token is valid

### AI generation fails:
- The system automatically provides fallback questions
- Check your internet connection
- Verify Hugging Face API token permissions

### Python backend won't start:
- Install Python 3.8+
- Install required packages: `pip install flask flask-cors python-dotenv requests`
- Check port 5000 is not in use

## 🎉 Success!

Once everything is set up, you can:
- Generate unlimited questions on any topic
- Create diverse question types automatically
- Save time on exam creation
- Ensure consistent question quality
- Focus on teaching while AI handles question generation

The AI integration makes your exam system incredibly powerful and flexible!
5 changes: 5 additions & 0 deletions COntent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# vibe coding for generating question paper generator by using title and there discription and also by using pdf file
* create a react project
* integrate multiple pages
* create backend at js and then it created the issue then
* integrate huggingface for i implement in a python as a backend and connect with the huggingface
89 changes: 89 additions & 0 deletions EXAM_SYSTEM_TEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 🎯 Exam System Testing Guide

## Quick Test Instructions

### 1. **Admin Testing**
Login as admin:
- Username: `admin`
- Password: `admin123`

**What you can do:**
- View admin dashboard with sample exams
- Create new exams (manual or AI-generated)
- Assign exams to students
- View exam statistics

### 2. **Student Testing**
Login as student:
- Username: `student`
- Password: `student123`

**What you can do:**
- View assigned exams (2 sample exams pre-assigned)
- Take exams with timer
- See results and performance

### 3. **Sample Exams Available**
1. **JavaScript Basics** (30 minutes)
- Multiple choice questions
- True/False questions
- Short answer questions

2. **Math Quiz** (20 minutes)
- Basic math problems
- Mixed question types

### 4. **Test the "Start Exam" Feature**
1. Login as `student/student123`
2. Go to Student Dashboard
3. Click "Start Exam" on any pending exam
4. The exam should now load properly without errors!

### 5. **AI Question Generation (Optional)**
1. Login as admin
2. Click "AI Generator" (purple button)
3. Enter any topic (e.g., "Python Programming")
4. Generate questions with AI
5. Questions are automatically added to exam library

## 🔧 What Was Fixed

### The "Start Exam" Error Issue:
- ✅ **Root Cause**: ExamTaking component was using API calls instead of localStorage
- ✅ **Solution**: Created `SimpleExamTaking` component for localStorage-based system
- ✅ **Data Structure**: Fixed exam/question structure mismatch
- ✅ **Context Methods**: Added `submitAttempt` method to ExamContext
- ✅ **Sample Data**: Added working sample exams for immediate testing

### Key Components:
- `SimpleExamTaking.js` - New exam taking interface (localStorage-based)
- `sampleData.js` - Pre-loaded test exams
- Updated `ExamContext.js` - Fixed data structures and added missing methods
- Updated `StudentDashboard.js` - Now uses SimpleExamTaking

## 🎉 Expected Results

**Before Fix:**
- Clicking "Start Exam" → Error/Crash
- API endpoint errors
- Missing exam data

**After Fix:**
- Clicking "Start Exam" → Beautiful exam interface loads
- Timer works correctly
- Questions display properly
- Answers can be submitted
- Results are calculated and stored
- No API dependencies needed

## 🚀 Ready to Test!

Your exam system is now fully functional with:
- ✅ Working exam taking interface
- ✅ Timer functionality
- ✅ Multiple question types
- ✅ Automatic scoring
- ✅ Results tracking
- ✅ AI question generation (bonus!)

Just login and start testing! 🎯
Loading