Spaces:
Sleeping
Sleeping
File size: 20,707 Bytes
459923e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
# Essay Analysis API - Exact JSON Format
## API Endpoints Overview
This API provides comprehensive essay analysis with the exact JSON format required by the web development team.
### Available Endpoints
1. **`/api/essay-analysis`** - Comprehensive essay analysis (supports optional question parameter)
2. **`/api/essay-analysis-with-question`** - **NEW** Comprehensive essay analysis based on a specific question
3. **`/api/feedback`** - Feedback generation (supports optional question parameter)
4. **`/api/feedback-with-question`** - **NEW** Feedback generation based on a specific question
## Updated API Endpoint: `/api/essay-analysis`
This endpoint now supports an optional question parameter for question-specific analysis.
### Request
- **Method**: POST
- **Content-Type**: application/x-www-form-urlencoded
- **Body**:
- `essay_text=<your_essay_text>` (required)
- `question=<your_specific_question>` (optional)
### Response Format
The API returns a JSON object with the following exact structure:
**When no question is provided (general analysis):**
```json
{
"originalEssayWordCount": 300,
"reWrittenEssayWordCount": 300,
"originalEssay": "Your original essay text here...",
"reWrittenEssay": "Your rewritten essay text here...",
"overallEssayEvaluationScore": 70,
"analysisType": "general",
"evaluationAndScoring": [
{
"label": "Grammar & Punctuation",
"score": 70,
"analysis": "Detailed analysis of grammar and punctuation",
"issuesCount": 2,
"issuesList": [
{
"before": "Original text with error",
"after": "Corrected text",
"explanation": "Why this change is needed"
}
],
"positivePoints": ["Specific examples of good grammar usage"]
}
],
"essayStructure": [
{
"label": "Introduction & Thesis",
"features": [
{
"label": "Clear Thesis Statement",
"isCorrect": true
},
{
"label": "Engaging Introduction",
"isCorrect": false,
"errorMessage": "Introduction should be more engaging and capture reader's attention."
}
]
}
],
"topicSpecificFeedback": {
"topicCoverage": "Detailed analysis of how well the topic is addressed",
"missingAspects": ["Aspects that could be better covered"],
"strengths": ["Specific strengths in topic handling"],
"improvementSuggestions": ["Specific suggestions for better topic coverage"]
}
}
```
**When a question is provided (question-specific analysis):**
```json
{
"originalEssayWordCount": 300,
"reWrittenEssayWordCount": 300,
"originalEssay": "Your original essay text here...",
"reWrittenEssay": "Your rewritten essay text here...",
"overallEssayEvaluationScore": 70,
"analysisType": "question_specific",
"question": "Your specific question here...",
"questionSpecificFeedback": {
"question": "Your specific question here...",
"question_relevance_score": 85,
"question_coverage": "Detailed analysis of how well the question is addressed",
"covered_aspects": ["Specific aspects of the question that are well covered"],
"missing_aspects": ["Aspects of the question that are missing or poorly addressed"],
"strengths": ["Specific strengths in addressing the question"],
"improvement_suggestions": ["Specific suggestions for better question coverage"]
},
"evaluationAndScoring": [
{
"label": "Grammar & Punctuation",
"score": 70,
"analysis": "Detailed analysis of grammar and punctuation",
"issuesCount": 2,
"issuesList": [
{
"before": "Original text with error",
"after": "Corrected text",
"explanation": "Why this change is needed"
}
],
"positivePoints": ["Specific examples of good grammar usage"]
}
],
"essayStructure": [
{
"label": "Introduction & Thesis",
"features": [
{
"label": "Clear Thesis Statement",
"isCorrect": true
},
{
"label": "Engaging Introduction",
"isCorrect": false,
"errorMessage": "Introduction should be more engaging and capture reader's attention."
}
]
}
]
}
```
## Updated API Endpoint: `/api/feedback`
This endpoint now supports an optional question parameter for question-specific feedback.
### Request
- **Method**: POST
- **Content-Type**: application/x-www-form-urlencoded
- **Body**:
- `essay_text=<your_essay_text>` (required)
- `question=<your_specific_question>` (optional)
### Response Format
**When no question is provided (general feedback):**
```json
{
"feedback": {
"sections": [
{
"name": "Grammar & Punctuation",
"score": 85,
"analysis": "Detailed analysis of grammar and punctuation",
"issues": [
{
"before": "Original text with error",
"after": "Corrected text",
"explanation": "Why this change is needed"
}
],
"positive_points": ["Specific examples of good grammar usage"],
"issues_count": 1
}
],
"overall_score": 82,
"essay_structure": {
"Introduction & Thesis": {
"Clear Thesis Statement": {
"value": true,
"explanation": "Thesis is clearly stated",
"suggestions": "Consider strengthening the thesis"
}
}
}
},
"feedback_type": "general",
"question": null,
"pdf_path": "/path/to/generated/pdf"
}
```
**When a question is provided (question-specific feedback):**
```json
{
"feedback": {
"sections": [
{
"name": "Grammar & Punctuation",
"score": 85,
"analysis": "Detailed analysis of grammar and punctuation",
"issues": [
{
"before": "Original text with error",
"after": "Corrected text",
"explanation": "Why this change is needed"
}
],
"positive_points": ["Specific examples of good grammar usage"],
"issues_count": 1
}
],
"overall_score": 82,
"essay_structure": {
"Introduction & Thesis": {
"Clear Thesis Statement": {
"value": true,
"explanation": "Thesis is clearly stated",
"suggestions": "Consider strengthening the thesis"
}
}
},
"question_specific_feedback": {
"question": "Your specific question here...",
"question_relevance_score": 85,
"question_coverage": "Detailed analysis of how well the question is addressed",
"covered_aspects": ["Specific aspects of the question that are well covered"],
"missing_aspects": ["Aspects of the question that are missing or poorly addressed"],
"strengths": ["Specific strengths in addressing the question"],
"improvement_suggestions": ["Specific suggestions for better question coverage"]
}
},
"feedback_type": "question_specific",
"question": "Your specific question here...",
"pdf_path": "/path/to/generated/pdf"
}
```
## New API Endpoint: `/api/essay-analysis-with-question`
This endpoint provides comprehensive essay analysis with the exact JSON format required by the web development team, but now includes question-specific evaluation.
### Request
- **Method**: POST
- **Content-Type**: application/x-www-form-urlencoded
- **Body**:
- `essay_text=<your_essay_text>`
- `question=<your_specific_question>`
### Response Format
The API returns a JSON object with the following exact structure:
```json
{
"originalEssayWordCount": 300,
"reWrittenEssayWordCount": 300,
"originalEssay": "Your original essay text here...",
"reWrittenEssay": "Your rewritten essay text here...",
"overallEssayEvaluationScore": 70,
"question": "Your specific question here...",
"questionSpecificFeedback": {
"question": "Your specific question here...",
"question_relevance_score": 85,
"question_coverage": "Detailed analysis of how well the question is addressed",
"covered_aspects": ["Specific aspects of the question that are well covered"],
"missing_aspects": ["Aspects of the question that are missing or poorly addressed"],
"strengths": ["Specific strengths in addressing the question"],
"improvement_suggestions": ["Specific suggestions for better question coverage"]
},
"evaluationAndScoring": [
{
"label": "Grammar & Punctuation",
"score": 70,
"analysis": "Detailed analysis of grammar and punctuation",
"issuesCount": 2,
"issuesList": [
{
"before": "Original text with error",
"after": "Corrected text",
"explanation": "Why this change is needed"
}
],
"positivePoints": ["Specific examples of good grammar usage"]
},
{
"label": "Vocabulary Usage",
"score": 75,
"analysis": "Detailed analysis of vocabulary usage",
"issuesCount": 1,
"issuesList": [
{
"before": "Original word/phrase",
"after": "Improved word/phrase",
"explanation": "Why this improvement is suggested"
}
],
"positivePoints": ["Specific examples of good vocabulary usage"]
},
{
"label": "Sentence Structure",
"score": 100,
"analysis": "Detailed analysis of sentence structure",
"issuesCount": 0,
"issuesList": [],
"positivePoints": ["Specific examples of good sentence structure"]
}
],
"essayStructure": [
{
"label": "Introduction & Thesis",
"features": [
{
"label": "Clear Thesis Statement",
"isCorrect": true
},
{
"label": "Engaging Introduction",
"isCorrect": false,
"errorMessage": "Introduction should be more engaging and capture reader's attention."
},
{
"label": "Background Context",
"isCorrect": true
}
]
},
{
"label": "Body Development",
"features": [
{
"label": "Topic Sentences",
"isCorrect": true
},
{
"label": "Supporting Evidence",
"isCorrect": true
},
{
"label": "Logical Flow",
"isCorrect": true
},
{
"label": "Paragraph Coherence",
"isCorrect": true
}
]
},
{
"label": "Content Quality",
"features": [
{
"label": "Relevance to Topic",
"isCorrect": true
},
{
"label": "Depth of Analysis",
"isCorrect": false,
"errorMessage": "Analysis could be deeper with more critical examination of the topic."
},
{
"label": "Use of Examples",
"isCorrect": true
},
{
"label": "Critical Thinking",
"isCorrect": true
}
]
},
{
"label": "Evidence & Citations",
"features": [
{
"label": "Factual Accuracy",
"isCorrect": true
},
{
"label": "Source Credibility",
"isCorrect": true
},
{
"label": "Proper Citations",
"isCorrect": false,
"errorMessage": "Citations should follow proper academic format."
},
{
"label": "Statistical Data",
"isCorrect": true
}
]
},
{
"label": "Conclusion",
"features": [
{
"label": "Summary of Arguments",
"isCorrect": true
},
{
"label": "Policy Recommendations",
"isCorrect": true
},
{
"label": "Future Implications",
"isCorrect": true
},
{
"label": "Strong Closing",
"isCorrect": true
}
]
}
]
}
```
## New API Endpoint: `/api/feedback-with-question`
This endpoint provides detailed feedback based on a specific question.
### Request
- **Method**: POST
- **Content-Type**: application/x-www-form-urlencoded
- **Body**:
- `essay_text=<your_essay_text>`
- `question=<your_specific_question>`
### Response Format
```json
{
"feedback": {
"sections": [
{
"name": "Grammar & Punctuation",
"score": 85,
"analysis": "Detailed analysis of grammar and punctuation",
"issues": [
{
"before": "Original text with error",
"after": "Corrected text",
"explanation": "Why this change is needed"
}
],
"positive_points": ["Specific examples of good grammar usage"],
"issues_count": 1
}
],
"overall_score": 82,
"essay_structure": {
"Introduction & Thesis": {
"Clear Thesis Statement": {
"value": true,
"explanation": "Thesis is clearly stated",
"suggestions": "Consider strengthening the thesis"
}
}
},
"question_specific_feedback": {
"question": "Your specific question here...",
"question_relevance_score": 85,
"question_coverage": "Detailed analysis of how well the question is addressed",
"covered_aspects": ["Specific aspects of the question that are well covered"],
"missing_aspects": ["Aspects of the question that are missing or poorly addressed"],
"strengths": ["Specific strengths in addressing the question"],
"improvement_suggestions": ["Specific suggestions for better question coverage"]
}
},
"question": "Your specific question here...",
"pdf_path": "/path/to/generated/pdf"
}
```
## Field Descriptions
### Top-level Fields (for essay-analysis-with-question)
- `originalEssayWordCount` (integer): Number of words in the original essay
- `reWrittenEssayWordCount` (integer): Number of words in the rewritten essay
- `originalEssay` (string): The original essay text submitted by the user
- `reWrittenEssay` (string): The AI-improved version of the essay
- `overallEssayEvaluationScore` (integer): Overall score from 0-100
- `question` (string): The specific question that was evaluated (only when question is provided)
- `questionSpecificFeedback` (object): Detailed feedback on how well the essay addresses the question (only when question is provided)
- `evaluationAndScoring` (array): Detailed evaluation in multiple categories
- `essayStructure` (array): Essay structure analysis
- `analysisType` (string): Either "general" or "question_specific"
### questionSpecificFeedback Object
- `question` (string): The specific question being evaluated
- `question_relevance_score` (integer): Score from 0-100 indicating how well the essay addresses the question
- `question_coverage` (string): Detailed analysis of question coverage
- `covered_aspects` (array): List of question aspects that are well covered
- `missing_aspects` (array): List of question aspects that are missing or poorly addressed
- `strengths` (array): List of strengths in addressing the question
- `improvement_suggestions` (array): List of suggestions for better question coverage
### evaluationAndScoring Array
Each item contains:
- `label` (string): Category name
- `score` (integer): Score from 0-100 for this category
- `analysis` (string): Detailed analysis of the category
- `issuesCount` (integer): Number of issues found
- `issuesList` (array): List of specific issues with before/after corrections and explanations
- `positivePoints` (array): List of positive aspects in this category
### essayStructure Array
Each item contains:
- `label` (string): Structure category name
- `features` (array): List of features evaluated in this category
- `label` (string): Feature name
- `isCorrect` (boolean): Whether the feature is correct
- `errorMessage` (string, optional): Error message if `isCorrect` is false
## Example Usage
### Testing the Updated Endpoints
```python
import requests
# Test the updated essay analysis endpoint without question
response = requests.post(
"http://localhost:8000/api/essay-analysis",
data={"essay_text": "Your essay text here..."},
headers={"Content-Type": "application/x-www-form-urlencoded"}
)
if response.status_code == 200:
result = response.json()
print(f"Overall Score: {result['overallEssayEvaluationScore']}")
print(f"Analysis Type: {result['analysisType']}")
# Test the updated essay analysis endpoint with question
response = requests.post(
"http://localhost:8000/api/essay-analysis",
data={
"essay_text": "Your essay text here...",
"question": "Discuss the impact of climate change on global economies."
},
headers={"Content-Type": "application/x-www-form-urlencoded"}
)
if response.status_code == 200:
result = response.json()
print(f"Overall Score: {result['overallEssayEvaluationScore']}")
print(f"Question: {result['question']}")
print(f"Question Relevance Score: {result['questionSpecificFeedback']['question_relevance_score']}")
print(f"Analysis Type: {result['analysisType']}")
# Test the updated feedback endpoint without question
response = requests.post(
"http://localhost:8000/api/feedback",
data={"essay_text": "Your essay text here..."},
headers={"Content-Type": "application/x-www-form-urlencoded"}
)
if response.status_code == 200:
result = response.json()
print(f"Feedback Type: {result['feedback_type']}")
print(f"Overall Score: {result['feedback']['overall_score']}")
# Test the updated feedback endpoint with question
response = requests.post(
"http://localhost:8000/api/feedback",
data={
"essay_text": "Your essay text here...",
"question": "Analyze the role of technology in modern education."
},
headers={"Content-Type": "application/x-www-form-urlencoded"}
)
if response.status_code == 200:
result = response.json()
print(f"Feedback Type: {result['feedback_type']}")
print(f"Question: {result['question']}")
print(f"Question Relevance Score: {result['feedback']['question_specific_feedback']['question_relevance_score']}")
```
### Testing the New Question-Specific Endpoint
```python
import requests
# Test the new question-specific API
response = requests.post(
"http://localhost:8000/api/essay-analysis-with-question",
data={
"essay_text": "Your essay text here...",
"question": "Discuss the impact of climate change on global economies."
},
headers={"Content-Type": "application/x-www-form-urlencoded"}
)
if response.status_code == 200:
result = response.json()
print(f"Overall Score: {result['overallEssayEvaluationScore']}")
print(f"Question: {result['question']}")
print(f"Question Relevance Score: {result['questionSpecificFeedback']['question_relevance_score']}")
print(f"Original Word Count: {result['originalEssayWordCount']}")
print(f"Rewritten Word Count: {result['reWrittenEssayWordCount']}")
```
### Testing the Feedback with Question Endpoint
```python
import requests
# Test the feedback with question API
response = requests.post(
"http://localhost:8000/api/feedback-with-question",
data={
"essay_text": "Your essay text here...",
"question": "Analyze the role of technology in modern education."
},
headers={"Content-Type": "application/x-www-form-urlencoded"}
)
if response.status_code == 200:
result = response.json()
print(f"Question: {result['question']}")
print(f"Overall Score: {result['feedback']['overall_score']}")
print(f"Question Relevance Score: {result['feedback']['question_specific_feedback']['question_relevance_score']}")
```
## Testing
Run the test script to verify the API format:
```bash
python test_api_format.py
```
This will test all endpoints including the updated existing endpoints and new question-specific ones and save the full responses to JSON files for inspection.
## Key Differences Between Endpoints
1. **Updated Existing Endpoints** (`/api/essay-analysis`, `/api/feedback`):
- Accept optional `question` parameter
- Provide general analysis/feedback when no question is provided
- Provide question-specific analysis/feedback when question is provided
- Include `analysisType` or `feedback_type` field to indicate the type of analysis
- Backward compatible with existing implementations
2. **New Question-Specific Endpoints** (`/api/essay-analysis-with-question`, `/api/feedback-with-question`):
- Require both `essay_text` and `question` parameters
- Always provide question-specific analysis and feedback
- Include question relevance scoring
- Focus on how well the essay addresses the specific question
- Provide detailed feedback on question coverage and missing aspects |