Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,49 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
def evaluate_code(question, code):
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
iface = gr.Interface(
|
8 |
fn=evaluate_code,
|
9 |
inputs=[
|
10 |
-
gr.Textbox(lines=2, placeholder="Enter the problem question here..."),
|
11 |
-
gr.Code(language="python")
|
|
|
12 |
],
|
13 |
outputs=gr.Textbox(label="Evaluation Result"),
|
14 |
-
title="Code Evaluator",
|
15 |
-
description="Enter a coding question
|
16 |
)
|
17 |
|
18 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import json
|
3 |
|
4 |
+
def evaluate_code(question, code, language):
|
5 |
+
# Check if code is empty
|
6 |
+
if not code.strip():
|
7 |
+
return json.dumps({
|
8 |
+
"stars": 0,
|
9 |
+
"feedback": "No code provided. Please submit your code solution."
|
10 |
+
})
|
11 |
+
|
12 |
+
# Build a prompt for the evaluator (this is where you would normally call TinyLlama)
|
13 |
+
prompt = f"""
|
14 |
+
You are an expert code evaluator.
|
15 |
+
Rate the user's solution to the following problem from 0-5 (0 = completely incorrect, 5 = excellent).
|
16 |
+
Also provide a concise "feedback" message.
|
17 |
+
Programming Language: {language}
|
18 |
+
Problem: "{question}"
|
19 |
+
Solution: "{code}"
|
20 |
+
Return ONLY valid JSON: {{"stars": number, "feedback": string}}
|
21 |
+
Do not include any extra text outside the JSON.
|
22 |
+
"""
|
23 |
+
# For demonstration purposes, we simulate the evaluation:
|
24 |
+
# (Replace the following with a call to your TinyLlama model)
|
25 |
+
if language.lower() == "python":
|
26 |
+
result = {"stars": 5, "feedback": "Excellent Python solution with clear logic and proper syntax."}
|
27 |
+
elif language.lower() == "c":
|
28 |
+
result = {"stars": 5, "feedback": "Great C code! The solution is correct with optimal use of functions and pointers."}
|
29 |
+
elif language.lower() == "java":
|
30 |
+
result = {"stars": 5, "feedback": "Excellent Java solution with proper class structure and error handling."}
|
31 |
+
else:
|
32 |
+
result = {"stars": 0, "feedback": "Language not supported."}
|
33 |
+
|
34 |
+
return json.dumps(result)
|
35 |
|
36 |
iface = gr.Interface(
|
37 |
fn=evaluate_code,
|
38 |
inputs=[
|
39 |
+
gr.Textbox(lines=2, placeholder="Enter the problem question here...", label="Question"),
|
40 |
+
gr.Code(language="python", label="Code"),
|
41 |
+
gr.Dropdown(choices=["c", "python", "java"], label="Language", value="python")
|
42 |
],
|
43 |
outputs=gr.Textbox(label="Evaluation Result"),
|
44 |
+
title="TinyLlama Code Evaluator",
|
45 |
+
description="Enter a coding question, your solution, and select a programming language to get AI-powered feedback."
|
46 |
)
|
47 |
|
48 |
+
if __name__ == "__main__":
|
49 |
+
iface.launch()
|