nryadav18 commited on
Commit
08fac8b
·
verified ·
1 Parent(s): cd57b63

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from llama_cpp import Llama
4
+
5
+ app = FastAPI()
6
+
7
+ # Download and initialize the model when the server starts
8
+ llm = Llama.from_pretrained(
9
+ repo_id="Qwen/Qwen2.5-Coder-1.5B-Instruct-GGUF",
10
+ filename="*q4_k_m.gguf", # 4-bit quantization for speed and low memory
11
+ n_ctx=2048 # Context window size
12
+ )
13
+
14
+ class EvalRequest(BaseModel):
15
+ task_description: str
16
+ python_code: str
17
+
18
+ @app.post("/evaluate")
19
+ async def evaluate_code(request: EvalRequest):
20
+ prompt = f"Task Description:\n{request.task_description}\n\nSubmitted Code:\n{request.python_code}\n\nEvaluate the code against the task. Assign a final score out of 10. Keep your feedback concise and helpful."
21
+
22
+ response = llm.create_chat_completion(
23
+ messages=[
24
+ # Framing the model specifically for grading student submissions
25
+ {"role": "system", "content": "You are an expert Python instructor. You evaluate student code submissions accurately, checking for logical correctness and task completion."},
26
+ {"role": "user", "content": prompt}
27
+ ],
28
+ max_tokens=250, # Limit response length to keep API fast
29
+ temperature=0.2 # Low temperature for consistent scoring
30
+ )
31
+
32
+ return {"evaluation": response['choices'][0]['message']['content']}