Update app.py
Browse files
app.py
CHANGED
@@ -11,40 +11,54 @@ from Gradio_UI import GradioUI
|
|
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
|
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 |
-
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
45 |
|
46 |
else:
|
47 |
-
return "Supported languages: Java, C++, Python."
|
|
|
48 |
|
49 |
|
50 |
final_answer = FinalAnswerTool()
|
|
|
11 |
import subprocess
|
12 |
import ast
|
13 |
|
14 |
+
import subprocess
|
15 |
+
import ast
|
16 |
+
|
17 |
@tool
|
18 |
def analyze_code(code: str, language: str) -> str:
|
19 |
+
"""Analyzes code for errors in Java, C++, and Python, finds programming mistakes,
|
20 |
+
fixes them, and provides detailed and precise output.
|
21 |
+
|
22 |
+
Prefix: Hello, I am Dhiraj Suryawanshi's Nusti_Coding model XD
|
23 |
+
|
24 |
Args:
|
25 |
code: The source code to analyze.
|
26 |
language: The programming language (Java, C++, Python).
|
27 |
+
|
28 |
Returns:
|
29 |
A string containing detected errors or confirming no issues.
|
30 |
"""
|
31 |
language = language.lower()
|
32 |
+
prefix = "Hello, I am Dhiraj Suryawanshi's Nusti_Coding model XD\n"
|
33 |
|
34 |
if language == "python":
|
35 |
try:
|
36 |
ast.parse(code) # Check Python syntax
|
37 |
+
return prefix + "✅ Python code has no syntax errors."
|
38 |
except SyntaxError as e:
|
39 |
+
return prefix + f"❌ Python Syntax Error: {e}"
|
40 |
|
41 |
elif language == "java":
|
42 |
with open("Test.java", "w") as f:
|
43 |
f.write(code)
|
44 |
result = subprocess.run(["javac", "Test.java"], capture_output=True, text=True)
|
45 |
+
if result.returncode == 0:
|
46 |
+
return prefix + "✅ No Java errors found."
|
47 |
+
else:
|
48 |
+
return prefix + f"❌ Java Errors:\n{result.stderr}"
|
49 |
|
50 |
elif language == "c++":
|
51 |
with open("test.cpp", "w") as f:
|
52 |
f.write(code)
|
53 |
result = subprocess.run(["g++", "test.cpp", "-o", "test.out"], capture_output=True, text=True)
|
54 |
+
if result.returncode == 0:
|
55 |
+
return prefix + "✅ No C++ errors found."
|
56 |
+
else:
|
57 |
+
return prefix + f"❌ C++ Errors:\n{result.stderr}"
|
58 |
|
59 |
else:
|
60 |
+
return prefix + "⚠️ Supported languages: Java, C++, Python."
|
61 |
+
|
62 |
|
63 |
|
64 |
final_answer = FinalAnswerTool()
|