Spaces:
Running
Running
docs: developer handoff API guide
Browse files- API.txt +49 -191
- test/test_submission.py +22 -0
- test/website.html +135 -0
API.txt
CHANGED
|
@@ -1,196 +1,54 @@
|
|
| 1 |
-
|
| 2 |
-
==================
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
|
|
|
| 6 |
|
| 7 |
-
WHAT IS THIS?
|
| 8 |
-
-------------
|
| 9 |
-
You send a code file + an optional question, and the API grades it using AI.
|
| 10 |
-
It tells you the score, what language it detected, whether the code is correct,
|
| 11 |
-
and lists any logic flaws or syntax errors it found.
|
| 12 |
|
| 13 |
-
|
| 14 |
-
BASE URL
|
| 15 |
-
--------
|
| 16 |
-
https://dhyandevp-codeevaluator.hf.space
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
BEFORE YOU START
|
| 20 |
-
----------------
|
| 21 |
-
You need an API key. Add it as a header in every request:
|
| 22 |
-
|
| 23 |
-
X-API-Key: your-key-here
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
HOW IT WORKS (2 STEPS)
|
| 27 |
-
----------------------
|
| 28 |
-
|
| 29 |
-
Step 1: Submit your code
|
| 30 |
-
Step 2: Poll for the result
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
STEP 1 — SUBMIT YOUR CODE
|
| 34 |
-
--------------------------
|
| 35 |
-
|
| 36 |
-
Send a POST request to /submit with your code file.
|
| 37 |
-
You can also include a question/objective to grade the code against.
|
| 38 |
-
|
| 39 |
-
curl -X POST https://dhyandevp-codeevaluator.hf.space/submit \
|
| 40 |
-
-H "X-API-Key: your-key-here" \
|
| 41 |
-
-F "file=@my_script.py" \
|
| 42 |
-
-F "question_objective=Write a function that returns the nth Fibonacci number"
|
| 43 |
-
|
| 44 |
-
You'll get back a job ID:
|
| 45 |
-
|
| 46 |
-
{
|
| 47 |
-
"job_id": "some-uuid-here",
|
| 48 |
-
"status": "Processing"
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
Save that job_id — you need it for step 2.
|
| 52 |
-
|
| 53 |
-
In Python:
|
| 54 |
-
|
| 55 |
-
import requests
|
| 56 |
-
|
| 57 |
-
resp = requests.post(
|
| 58 |
-
"https://dhyandevp-codeevaluator.hf.space/submit",
|
| 59 |
-
headers={"X-API-Key": "your-key-here"},
|
| 60 |
-
files={"file": open("my_script.py", "rb")},
|
| 61 |
-
data={"question_objective": "Write a function that returns the nth Fibonacci number"},
|
| 62 |
-
)
|
| 63 |
-
job_id = resp.json()["job_id"]
|
| 64 |
-
print("Job ID:", job_id)
|
| 65 |
-
|
| 66 |
-
Notes:
|
| 67 |
-
- Any code file works (Python, JavaScript, C++, Rust, Go, etc.)
|
| 68 |
-
- Max file size: 100 KB
|
| 69 |
-
- The question_objective is optional. Skip it if you just want a general review.
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
STEP 2 — GET THE RESULT
|
| 73 |
-
------------------------
|
| 74 |
-
|
| 75 |
-
Poll GET /report/{job_id} every few seconds until it's done.
|
| 76 |
-
|
| 77 |
-
curl https://dhyandevp-codeevaluator.hf.space/report/YOUR_JOB_ID \
|
| 78 |
-
-H "X-API-Key: your-key-here"
|
| 79 |
-
|
| 80 |
-
If it's still working:
|
| 81 |
-
|
| 82 |
-
{
|
| 83 |
-
"job_id": "...",
|
| 84 |
-
"status": "Processing",
|
| 85 |
-
"message": "Your submission is being evaluated. Retry in a few seconds."
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
When it's done:
|
| 89 |
-
|
| 90 |
-
{
|
| 91 |
-
"job_id": "...",
|
| 92 |
-
"status": "Completed",
|
| 93 |
-
"report": {
|
| 94 |
-
"language_detected": "Python",
|
| 95 |
-
"is_correct": true,
|
| 96 |
-
"score": 82.50,
|
| 97 |
-
"percentage": "82.50%",
|
| 98 |
-
"logic_flaws": [
|
| 99 |
-
"Does not handle negative input — will recurse infinitely."
|
| 100 |
-
],
|
| 101 |
-
"syntax_errors": [],
|
| 102 |
-
"student_feedback": "Solid implementation but lacks input validation."
|
| 103 |
-
}
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
If something went wrong:
|
| 107 |
-
|
| 108 |
-
{
|
| 109 |
-
"job_id": "...",
|
| 110 |
-
"status": "Failed",
|
| 111 |
-
"error": {
|
| 112 |
-
"error_type": "ValueError",
|
| 113 |
-
"error_message": "LLM response missing required keys..."
|
| 114 |
-
}
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
In Python (polling loop):
|
| 118 |
-
|
| 119 |
-
import time, requests
|
| 120 |
-
|
| 121 |
-
headers = {"X-API-Key": "your-key-here"}
|
| 122 |
-
url = f"https://dhyandevp-codeevaluator.hf.space/report/{job_id}"
|
| 123 |
-
|
| 124 |
-
while True:
|
| 125 |
-
data = requests.get(url, headers=headers).json()
|
| 126 |
-
|
| 127 |
-
if data["status"] == "Completed":
|
| 128 |
-
r = data["report"]
|
| 129 |
-
print(f"Language: {r['language_detected']}")
|
| 130 |
-
print(f"Correct: {r['is_correct']}")
|
| 131 |
-
print(f"Score: {r['score']}")
|
| 132 |
-
for flaw in r["logic_flaws"]:
|
| 133 |
-
print(f" - {flaw}")
|
| 134 |
-
break
|
| 135 |
-
|
| 136 |
-
if data["status"] == "Failed":
|
| 137 |
-
print("Error:", data["error"]["error_message"])
|
| 138 |
-
break
|
| 139 |
-
|
| 140 |
-
print("Still grading... waiting 5 seconds")
|
| 141 |
-
time.sleep(5)
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
WHAT THE REPORT FIELDS MEAN
|
| 145 |
-
----------------------------
|
| 146 |
-
|
| 147 |
-
language_detected — What language the AI thinks your code is written in.
|
| 148 |
-
|
| 149 |
-
is_correct — Did the code actually do what the question asked?
|
| 150 |
-
true = yes, false = no.
|
| 151 |
-
|
| 152 |
-
score — A number from 0 to 100. Higher is better.
|
| 153 |
-
90-100 Excellent
|
| 154 |
-
70-89 Good
|
| 155 |
-
50-69 Okay
|
| 156 |
-
30-49 Poor
|
| 157 |
-
0-29 Broken
|
| 158 |
-
|
| 159 |
-
percentage — Same as score but as a string like "82.50%".
|
| 160 |
-
|
| 161 |
-
logic_flaws — Things wrong with the logic (e.g. infinite loops,
|
| 162 |
-
wrong output, missing edge cases). Empty list if none.
|
| 163 |
-
|
| 164 |
-
syntax_errors — Code that won't compile or has bad syntax.
|
| 165 |
-
Empty list if none.
|
| 166 |
-
|
| 167 |
-
student_feedback — A short paragraph explaining the grade.
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
HEALTH CHECK
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Hey [Name],
|
|
|
|
| 2 |
|
| 3 |
+
The Code Evaluator API backend is deployed and ready for frontend integration.
|
| 4 |
+
The evaluation takes a little time to process, so the flow requires submitting
|
| 5 |
+
the file first and then polling a second endpoint for the results.
|
| 6 |
|
| 7 |
+
Here is the integration breakdown:
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
Core Details
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
------------
|
| 12 |
+
Base URL: https://dhyandevp-codeevaluator.hf.space
|
| 13 |
+
Swagger Docs: https://dhyandevp-codeevaluator.hf.space/docs
|
| 14 |
+
Auth: Include the header X-API-Key: your-key-here in all requests.
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Step 1: Submit the Code
|
| 18 |
+
-----------------------
|
| 19 |
+
Endpoint: POST /submit
|
| 20 |
+
Payload Type: multipart/form-data
|
| 21 |
+
Fields Required: file (any code file, max 100 KB).
|
| 22 |
+
Fields Optional: question_objective (pass the plain text question here to grade the logic against it).
|
| 23 |
+
Response: It will return a job_id and a status of Processing. Save this ID for step two.
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
Step 2: Poll for the Result
|
| 27 |
+
---------------------------
|
| 28 |
+
Endpoint: GET /report/{job_id}
|
| 29 |
+
Logic: Poll this endpoint every few seconds.
|
| 30 |
+
Pending State: Returns {"status": "Processing"}.
|
| 31 |
+
Error State: Returns {"status": "Failed"} along with an error_message.
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
The Data Contract (Completed State)
|
| 35 |
+
-----------------------------------
|
| 36 |
+
Once the evaluation is finished, the polling endpoint will return
|
| 37 |
+
{"status": "Completed"} and hand off the report object. Here is the exact
|
| 38 |
+
schema you will use to build the UI components:
|
| 39 |
+
|
| 40 |
+
{
|
| 41 |
+
"job_id": "some-uuid-here",
|
| 42 |
+
"status": "Completed",
|
| 43 |
+
"report": {
|
| 44 |
+
"language_detected": "Python",
|
| 45 |
+
"is_correct": true,
|
| 46 |
+
"score": 82.50,
|
| 47 |
+
"percentage": "82.50%",
|
| 48 |
+
"logic_flaws": [
|
| 49 |
+
"Does not handle negative input — will recurse infinitely."
|
| 50 |
+
],
|
| 51 |
+
"syntax_errors": [],
|
| 52 |
+
"student_feedback": "Solid implementation but lacks input validation."
|
| 53 |
+
}
|
| 54 |
+
}
|
test/test_submission.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def merge_intervals(intervals):
|
| 2 |
+
# Handle zero or single element edge cases safely
|
| 3 |
+
if len(intervals) <= 1:
|
| 4 |
+
return intervals
|
| 5 |
+
|
| 6 |
+
# Initialize the tracking array with the first element
|
| 7 |
+
merged_collection = [intervals[0]]
|
| 8 |
+
|
| 9 |
+
# Loop through the remaining intervals to check for overlaps
|
| 10 |
+
for current_interval in intervals[1:]:
|
| 11 |
+
previous_merged = merged_collection[-1]
|
| 12 |
+
|
| 13 |
+
# If the start of the current interval is less than or equal to
|
| 14 |
+
# the end of the previous interval, an overlap occurs.
|
| 15 |
+
if current_interval[0] <= previous_merged[1]:
|
| 16 |
+
# Merge the intervals by updating the end boundary
|
| 17 |
+
previous_merged[1] = max(previous_merged[1], current_interval[1])
|
| 18 |
+
else:
|
| 19 |
+
# No overlap detected, append the standalone interval
|
| 20 |
+
merged_collection.append(current_interval)
|
| 21 |
+
|
| 22 |
+
return merged_collection
|
test/website.html
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Accessible Pricing Cards</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--bg-color: #ffffff;
|
| 10 |
+
--text-color: #333333;
|
| 11 |
+
--card-bg: #f9f9f9;
|
| 12 |
+
--border-color: #e0e0e0;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body.dark-theme {
|
| 16 |
+
--bg-color: #121212;
|
| 17 |
+
--text-color: #e0e0e0;
|
| 18 |
+
--card-bg: #1e1e1e;
|
| 19 |
+
--border-color: #333333;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
body {
|
| 23 |
+
background-color: var(--bg-color);
|
| 24 |
+
color: var(--text-color);
|
| 25 |
+
font-family: system-ui, -apple-system, sans-serif;
|
| 26 |
+
margin: 0;
|
| 27 |
+
padding: 2rem;
|
| 28 |
+
transition: background-color 0.3s, color 0.3s;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
header {
|
| 32 |
+
display: flex;
|
| 33 |
+
justify-content: space-between;
|
| 34 |
+
align-items: center;
|
| 35 |
+
margin-bottom: 2rem;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
button {
|
| 39 |
+
padding: 0.5rem 1rem;
|
| 40 |
+
cursor: pointer;
|
| 41 |
+
border: 1px solid var(--border-color);
|
| 42 |
+
background: var(--card-bg);
|
| 43 |
+
color: var(--text-color);
|
| 44 |
+
border-radius: 4px;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.pricing-grid {
|
| 48 |
+
display: grid;
|
| 49 |
+
grid-template-columns: 1fr;
|
| 50 |
+
gap: 2rem;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
@media (min-width: 768px) {
|
| 54 |
+
.pricing-grid {
|
| 55 |
+
grid-template-columns: repeat(3, 1fr);
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.card {
|
| 60 |
+
background-color: var(--card-bg);
|
| 61 |
+
border: 1px solid var(--border-color);
|
| 62 |
+
border-radius: 8px;
|
| 63 |
+
padding: 2rem;
|
| 64 |
+
text-align: center;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
ul {
|
| 68 |
+
list-style: none;
|
| 69 |
+
padding: 0;
|
| 70 |
+
text-align: left;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
li {
|
| 74 |
+
padding: 0.5rem 0;
|
| 75 |
+
border-bottom: 1px solid var(--border-color);
|
| 76 |
+
}
|
| 77 |
+
</style>
|
| 78 |
+
</head>
|
| 79 |
+
<body>
|
| 80 |
+
|
| 81 |
+
<header>
|
| 82 |
+
<h1>Our Pricing Plans</h1>
|
| 83 |
+
<button id="themeToggle" aria-pressed="false">Toggle Dark Mode</button>
|
| 84 |
+
</header>
|
| 85 |
+
|
| 86 |
+
<main>
|
| 87 |
+
<section class="pricing-grid" aria-label="Pricing Options">
|
| 88 |
+
|
| 89 |
+
<article class="card">
|
| 90 |
+
<h2>Basic</h2>
|
| 91 |
+
<p class="price"><strong>$9.99 / mo</strong></p>
|
| 92 |
+
<ul>
|
| 93 |
+
<li>1 User Account</li>
|
| 94 |
+
<li>5GB Storage</li>
|
| 95 |
+
<li>Standard Support</li>
|
| 96 |
+
</ul>
|
| 97 |
+
</article>
|
| 98 |
+
|
| 99 |
+
<article class="card">
|
| 100 |
+
<h2>Pro</h2>
|
| 101 |
+
<p class="price"><strong>$19.99 / mo</strong></p>
|
| 102 |
+
<ul>
|
| 103 |
+
<li>5 User Accounts</li>
|
| 104 |
+
<li>50GB Storage</li>
|
| 105 |
+
<li>Priority Support</li>
|
| 106 |
+
</ul>
|
| 107 |
+
</article>
|
| 108 |
+
|
| 109 |
+
<article class="card">
|
| 110 |
+
<h2>Enterprise</h2>
|
| 111 |
+
<p class="price"><strong>$49.99 / mo</strong></p>
|
| 112 |
+
<ul>
|
| 113 |
+
<li>Unlimited Users</li>
|
| 114 |
+
<li>500GB Storage</li>
|
| 115 |
+
<li>24/7 Dedicated Support</li>
|
| 116 |
+
</ul>
|
| 117 |
+
</article>
|
| 118 |
+
|
| 119 |
+
</section>
|
| 120 |
+
</main>
|
| 121 |
+
|
| 122 |
+
<footer>
|
| 123 |
+
<p>© 2026 SaaS Company. All rights reserved.</p>
|
| 124 |
+
</footer>
|
| 125 |
+
|
| 126 |
+
<script>
|
| 127 |
+
const toggleButton = document.getElementById('themeToggle');
|
| 128 |
+
|
| 129 |
+
toggleButton.addEventListener('click', () => {
|
| 130 |
+
const isDarkMode = document.body.classList.toggle('dark-theme');
|
| 131 |
+
toggleButton.setAttribute('aria-pressed', isDarkMode);
|
| 132 |
+
});
|
| 133 |
+
</script>
|
| 134 |
+
</body>
|
| 135 |
+
</html>
|