Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,64 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
-
from duckduckgo_search import DDGS
|
8 |
-
import re
|
9 |
from Gradio_UI import GradioUI
|
10 |
-
|
|
|
11 |
|
|
|
12 |
@tool
|
13 |
-
def
|
14 |
-
"""
|
15 |
-
|
16 |
-
|
17 |
Args:
|
18 |
-
|
19 |
-
|
20 |
-
n: The number of results to return.
|
21 |
-
budget: If True, modifies the query to focus on budget friendly options.
|
22 |
-
|
23 |
Returns:
|
24 |
-
A
|
25 |
"""
|
26 |
-
|
27 |
-
|
28 |
-
raise ValueError("Invalid category. Choose from: places, food, museum.")
|
29 |
-
|
30 |
-
# Modify the query if budget-friendly options are desired.
|
31 |
-
if budget:
|
32 |
-
query = f"top {n} budget friendly {category} in {city}"
|
33 |
-
else:
|
34 |
-
query = f"top {n} {category} in {city}"
|
35 |
-
|
36 |
-
with DDGS() as ddgs:
|
37 |
-
results = ddgs.text(query, max_results=n)
|
38 |
-
return [f"{result['title']} - {result['href']}" for result in results]
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
|
56 |
final_answer = FinalAnswerTool()
|
@@ -59,13 +67,12 @@ final_answer = FinalAnswerTool()
|
|
59 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
60 |
|
61 |
model = HfApiModel(
|
62 |
-
max_tokens=2096,
|
63 |
-
temperature=0.5,
|
64 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
65 |
-
custom_role_conversions=None,
|
66 |
)
|
67 |
|
68 |
-
|
69 |
# Import tool from Hub
|
70 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
71 |
|
@@ -74,8 +81,8 @@ with open("prompts.yaml", 'r') as stream:
|
|
74 |
|
75 |
agent = CodeAgent(
|
76 |
model=model,
|
77 |
-
tools=[final_answer
|
78 |
-
max_steps=
|
79 |
verbosity_level=1,
|
80 |
grammar=None,
|
81 |
planning_interval=None,
|
@@ -84,5 +91,4 @@ agent = CodeAgent(
|
|
84 |
prompt_templates=prompt_templates
|
85 |
)
|
86 |
|
87 |
-
|
88 |
GradioUI(agent).launch()
|
|
|
1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
7 |
from Gradio_UI import GradioUI
|
8 |
+
import subprocess
|
9 |
+
import ast
|
10 |
|
11 |
+
# Below is a tool that analyze code and Find mistakes and fix it named as Nusti_Coding_Model By Dhiraj Suryawanshi XD!
|
12 |
@tool
|
13 |
+
def analyze_code(code: str, language: str) -> str:
|
14 |
+
"""Analyzes code for errors in MATLAB, Java, C++, and Python, finds programming mistakes,
|
15 |
+
fixes them, and provides detailed and precise output.
|
16 |
+
use prefix: Hello, I am Dhiraj Suryawanshi's Nusti_Coding model XD
|
17 |
Args:
|
18 |
+
code: The source code to analyze.
|
19 |
+
language: The programming language (MATLAB, Java, C++, Python).
|
|
|
|
|
|
|
20 |
Returns:
|
21 |
+
A string containing detected errors or confirming no issues.
|
22 |
"""
|
23 |
+
language = language.lower()
|
24 |
+
prefix = "Hello, I am Dhiraj Suryawanshi's Nusti_Coding model XD\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
if language == "python":
|
27 |
+
try:
|
28 |
+
ast.parse(code) # Check Python syntax
|
29 |
+
return prefix + "✅ Python code has no syntax errors."
|
30 |
+
except SyntaxError as e:
|
31 |
+
return prefix + f"❌ Python Syntax Error: {e}"
|
32 |
+
|
33 |
+
elif language == "java":
|
34 |
+
with open("Test.java", "w") as f:
|
35 |
+
f.write(code)
|
36 |
+
result = subprocess.run(["javac", "Test.java"], capture_output=True, text=True)
|
37 |
+
if result.returncode == 0:
|
38 |
+
return prefix + "✅ No Java errors found."
|
39 |
+
else:
|
40 |
+
return prefix + f"❌ Java Errors:\n{result.stderr}"
|
41 |
+
|
42 |
+
elif language == "c++":
|
43 |
+
with open("test.cpp", "w") as f:
|
44 |
+
f.write(code)
|
45 |
+
result = subprocess.run(["g++", "test.cpp", "-o", "test.out"], capture_output=True, text=True)
|
46 |
+
if result.returncode == 0:
|
47 |
+
return prefix + "✅ No C++ errors found."
|
48 |
+
else:
|
49 |
+
return prefix + f"❌ C++ Errors:\n{result.stderr}"
|
50 |
+
|
51 |
+
elif language == "matlab":
|
52 |
+
with open("test.m", "w") as f:
|
53 |
+
f.write(code)
|
54 |
+
result = subprocess.run(["matlab", "-batch", "test"], capture_output=True, text=True)
|
55 |
+
if result.returncode == 0:
|
56 |
+
return prefix + "✅ No MATLAB errors found."
|
57 |
+
else:
|
58 |
+
return prefix + f"❌ MATLAB Errors:\n{result.stderr}"
|
59 |
+
|
60 |
+
else:
|
61 |
+
return prefix + "⚠️ Supported languages: MATLAB, Java, C++, Python."
|
62 |
|
63 |
|
64 |
final_answer = FinalAnswerTool()
|
|
|
67 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
68 |
|
69 |
model = HfApiModel(
|
70 |
+
max_tokens=2096,
|
71 |
+
temperature=0.5,
|
72 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
|
73 |
+
custom_role_conversions=None,
|
74 |
)
|
75 |
|
|
|
76 |
# Import tool from Hub
|
77 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
78 |
|
|
|
81 |
|
82 |
agent = CodeAgent(
|
83 |
model=model,
|
84 |
+
tools=[final_answer], ## add your tools here (don't remove final answer)
|
85 |
+
max_steps=6,
|
86 |
verbosity_level=1,
|
87 |
grammar=None,
|
88 |
planning_interval=None,
|
|
|
91 |
prompt_templates=prompt_templates
|
92 |
)
|
93 |
|
|
|
94 |
GradioUI(agent).launch()
|