File size: 2,012 Bytes
5900202
2b461c6
5900202
2b461c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5900202
 
fc0d268
5900202
2b461c6
 
 
5900202
fc0d268
2b461c6
 
5900202
 
2b461c6
 
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
import gradio as gr
import json

def evaluate_code(question, code, language):
    # Check if code is empty
    if not code.strip():
        return json.dumps({
            "stars": 0,
            "feedback": "No code provided. Please submit your code solution."
        })
    
    # Build a prompt for the evaluator (this is where you would normally call TinyLlama)
    prompt = f"""
You are an expert code evaluator.
Rate the user's solution to the following problem from 0-5 (0 = completely incorrect, 5 = excellent).
Also provide a concise "feedback" message.
Programming Language: {language}
Problem: "{question}"
Solution: "{code}"
Return ONLY valid JSON: {{"stars": number, "feedback": string}}
Do not include any extra text outside the JSON.
"""
    # For demonstration purposes, we simulate the evaluation:
    # (Replace the following with a call to your TinyLlama model)
    if language.lower() == "python":
        result = {"stars": 5, "feedback": "Excellent Python solution with clear logic and proper syntax."}
    elif language.lower() == "c":
        result = {"stars": 5, "feedback": "Great C code! The solution is correct with optimal use of functions and pointers."}
    elif language.lower() == "java":
        result = {"stars": 5, "feedback": "Excellent Java solution with proper class structure and error handling."}
    else:
        result = {"stars": 0, "feedback": "Language not supported."}
    
    return json.dumps(result)

iface = gr.Interface(
    fn=evaluate_code,
    inputs=[
        gr.Textbox(lines=2, placeholder="Enter the problem question here...", label="Question"),
        gr.Code(language="python", label="Code"),
        gr.Dropdown(choices=["c", "python", "java"], label="Language", value="python")
    ],
    outputs=gr.Textbox(label="Evaluation Result"),
    title="TinyLlama Code Evaluator",
    description="Enter a coding question, your solution, and select a programming language to get AI-powered feedback."
)

if __name__ == "__main__":
    iface.launch()