Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
-
import json
|
3 |
|
4 |
-
def evaluate_code(question, code
|
5 |
-
# Check if code is
|
6 |
if not code.strip():
|
7 |
-
return
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 |
-
|
31 |
else:
|
32 |
-
|
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(
|
41 |
-
gr.Dropdown(choices=["c", "python", "java"], label="Language", value="python")
|
42 |
],
|
43 |
outputs=gr.Textbox(label="Evaluation Result"),
|
44 |
-
title="
|
45 |
-
description="Enter a coding question
|
46 |
)
|
47 |
|
48 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
def evaluate_code(language, question, code):
|
4 |
+
# Check if code is provided
|
5 |
if not code.strip():
|
6 |
+
return "Error: No code provided. Please enter your solution code."
|
7 |
+
|
8 |
+
# Dummy evaluation logic based on language.
|
9 |
+
# Replace this with your TinyLlama integration later.
|
10 |
+
if language.lower() == "c":
|
11 |
+
return "C evaluation: The code meets basic criteria but may need improvements."
|
12 |
+
elif language.lower() == "python":
|
13 |
+
return "Python evaluation: Code is correct and follows best practices."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
elif language.lower() == "java":
|
15 |
+
return "Java evaluation: Good structure, but consider error handling improvements."
|
16 |
else:
|
17 |
+
return "Unsupported language. Please select C, Python, or Java."
|
|
|
|
|
18 |
|
19 |
iface = gr.Interface(
|
20 |
fn=evaluate_code,
|
21 |
inputs=[
|
22 |
+
gr.Dropdown(choices=["C", "Python", "Java"], label="Language"),
|
23 |
gr.Textbox(lines=2, placeholder="Enter the problem question here...", label="Question"),
|
24 |
+
gr.Code(label="Your Code (if any)") # No placeholder property here.
|
|
|
25 |
],
|
26 |
outputs=gr.Textbox(label="Evaluation Result"),
|
27 |
+
title="Code Evaluator",
|
28 |
+
description="Enter a coding question and your solution (if available) to get AI-powered feedback. Supports C, Python, and Java."
|
29 |
)
|
30 |
|
31 |
if __name__ == "__main__":
|