Update app.py
Browse files
app.py
CHANGED
@@ -8,39 +8,43 @@ from tools.final_answer import FinalAnswerTool
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
# Below is an example of a tool that analyze code. !
|
|
|
|
|
|
|
11 |
@tool
|
12 |
def analyze_code(code: str, language: str) -> str:
|
13 |
-
"""Analyzes
|
14 |
|
15 |
Args:
|
16 |
code: The source code to analyze.
|
17 |
-
language: The programming language
|
18 |
|
19 |
Returns:
|
20 |
-
A string containing detected
|
21 |
"""
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
return
|
42 |
|
43 |
-
|
|
|
44 |
|
45 |
|
46 |
final_answer = FinalAnswerTool()
|
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
# Below is an example of a tool that analyze code. !
|
11 |
+
import subprocess
|
12 |
+
import ast
|
13 |
+
|
14 |
@tool
|
15 |
def analyze_code(code: str, language: str) -> str:
|
16 |
+
"""Analyzes code for errors in Java, C++, and Python.and find any programming mistakes and fix it and give output in detailed and precise manner and start with Prefix: Hello Iam Dhiraj Suryawanshi's Nusti_Coding model XD
|
17 |
|
18 |
Args:
|
19 |
code: The source code to analyze.
|
20 |
+
language: The programming language (Java, C++, Python).
|
21 |
|
22 |
Returns:
|
23 |
+
A string containing detected errors or confirming no issues.
|
24 |
"""
|
25 |
+
language = language.lower()
|
26 |
+
|
27 |
+
if language == "python":
|
28 |
+
try:
|
29 |
+
ast.parse(code) # Check Python syntax
|
30 |
+
return "Python code has no syntax errors."
|
31 |
+
except SyntaxError as e:
|
32 |
+
return f"Python Syntax Error: {e}"
|
33 |
+
|
34 |
+
elif language == "java":
|
35 |
+
with open("Test.java", "w") as f:
|
36 |
+
f.write(code)
|
37 |
+
result = subprocess.run(["javac", "Test.java"], capture_output=True, text=True)
|
38 |
+
return "No Java errors found." if result.returncode == 0 else f"Java Errors:\n{result.stderr}"
|
39 |
+
|
40 |
+
elif language == "c++":
|
41 |
+
with open("test.cpp", "w") as f:
|
42 |
+
f.write(code)
|
43 |
+
result = subprocess.run(["g++", "test.cpp", "-o", "test.out"], capture_output=True, text=True)
|
44 |
+
return "No C++ errors found." if result.returncode == 0 else f"C++ Errors:\n{result.stderr}"
|
45 |
|
46 |
+
else:
|
47 |
+
return "Supported languages: Java, C++, Python."
|
48 |
|
49 |
|
50 |
final_answer = FinalAnswerTool()
|