umgefahren commited on
Commit
c7e4c90
Β·
unverified Β·
1 Parent(s): 1da23df
Files changed (5) hide show
  1. .gitignore +2 -0
  2. Dockerfile +6 -3
  3. agent.py +16 -11
  4. main.py +2 -12
  5. uv.lock +0 -0
.gitignore CHANGED
@@ -8,3 +8,5 @@ wheels/
8
 
9
  # Virtual environments
10
  .venv
 
 
 
8
 
9
  # Virtual environments
10
  .venv
11
+
12
+ .env.local
Dockerfile CHANGED
@@ -4,6 +4,8 @@ RUN apk add curl python3
4
 
5
  RUN curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
6
 
 
 
7
  RUN adduser -u 1000 -D user
8
 
9
  USER user
@@ -11,6 +13,7 @@ USER user
11
  ENV HOME=/home/user \
12
  PATH=/home/user/.local/bin/:$PATH
13
 
 
14
  WORKDIR $HOME/app
15
 
16
  COPY --chown=user pyproject.toml .
@@ -19,9 +22,9 @@ RUN uv sync
19
 
20
  COPY --chown=user *.py .
21
 
22
- ENV GOOGLE_GENAI_USE_VERTEXAI=TRUE
23
- ENV GOOGLE_CLOUD_LOCATION=us-central1
24
- ENV GOOGLE_CLOUD_PROJECT=vibecoder-459110
25
  ENV GRADIO_SERVER_NAME="0.0.0.0"
26
 
27
  CMD ["uv", "run", "main.py"]
 
4
 
5
  RUN curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
6
 
7
+ RUN arduino-cli core install arduino:avr
8
+
9
  RUN adduser -u 1000 -D user
10
 
11
  USER user
 
13
  ENV HOME=/home/user \
14
  PATH=/home/user/.local/bin/:$PATH
15
 
16
+
17
  WORKDIR $HOME/app
18
 
19
  COPY --chown=user pyproject.toml .
 
22
 
23
  COPY --chown=user *.py .
24
 
25
+ ENV GOOGLE_GENAI_USE_VERTEXAI=FALSE
26
+ # ENV GOOGLE_CLOUD_LOCATION=us-central1
27
+ # ENV GOOGLE_CLOUD_PROJECT=vibecoder-459110
28
  ENV GRADIO_SERVER_NAME="0.0.0.0"
29
 
30
  CMD ["uv", "run", "main.py"]
agent.py CHANGED
@@ -4,8 +4,6 @@ from google.adk.runners import Runner
4
  from google.adk.tools import (
5
  ToolContext,
6
  FunctionTool,
7
- built_in_code_execution,
8
- google_search,
9
  )
10
  from google.genai import types
11
  import asyncio
@@ -13,18 +11,19 @@ import dotenv
13
  import os
14
  import subprocess
15
  import shutil
 
16
 
17
  dotenv.load_dotenv()
18
 
19
 
20
- def read_code(tool_context: ToolContext, start_line: int = 0, end_line: int = 9999999):
21
  """
22
  Read the code written so far. The code is arduino code.
23
  You can optionally select which part of the code you would like to get.
24
 
25
  Args:
26
- start_line (int): The first line of the code part you want (defaults to 0)
27
- end_line (int): The last line of the code part you want (defaults to infinity)
28
 
29
  Returns:
30
  str: The (part of the) code written so far.
@@ -304,28 +303,34 @@ def compile_with_arduino(
304
 
305
  code = tool_context.state.get("code")
306
  if not code:
307
- return {"error": "No code to compile"}
308
-
 
 
309
 
310
- shutil.rmtree('/tmp/arduino_project')
311
- os.mkdir('/tmp/arduino_project')
 
312
 
313
- with open("/tmp/arduino_project/arduino_project.ino", "w") as f:
314
  f.write(code)
315
 
316
  # Compile with the Arduino CLI
317
  result = subprocess.run(
318
- ["arduino-cli", "compile", "--fqbn", "arduino:avr:uno", "/tmp/arduino_project", "--build-path", "/tmp/arduino_project/output"],
319
  capture_output=True,
320
  )
321
  if result.returncode != 0:
 
322
  return {
 
323
  "error": "Compilation failed",
324
  "output": result.stderr.decode("utf-8"),
325
  }
326
  return {
327
  "success": True,
328
  "output": result.stdout.decode("utf-8"),
 
329
  }
330
 
331
  def search_library(
 
4
  from google.adk.tools import (
5
  ToolContext,
6
  FunctionTool,
 
 
7
  )
8
  from google.genai import types
9
  import asyncio
 
11
  import os
12
  import subprocess
13
  import shutil
14
+ import tempfile
15
 
16
  dotenv.load_dotenv()
17
 
18
 
19
+ def read_code(tool_context: ToolContext, start_line: int, end_line: int):
20
  """
21
  Read the code written so far. The code is arduino code.
22
  You can optionally select which part of the code you would like to get.
23
 
24
  Args:
25
+ start_line (int): The first line of the code part you want
26
+ end_line (int): The last line of the code part you want
27
 
28
  Returns:
29
  str: The (part of the) code written so far.
 
303
 
304
  code = tool_context.state.get("code")
305
  if not code:
306
+ return {
307
+ "success": False,
308
+ "error": "No code to compile"}
309
+
310
 
311
+ project_dir = tempfile.mkdtemp()
312
+ project_dir = f"{project_dir}/arduino_project"
313
+ os.makedirs(project_dir, exist_ok=True)
314
 
315
+ with open(f"{project_dir}/arduino_project.ino", "w") as f:
316
  f.write(code)
317
 
318
  # Compile with the Arduino CLI
319
  result = subprocess.run(
320
+ ["arduino-cli", "compile", "--fqbn", "arduino:avr:uno", project_dir, "--build-path", f"{project_dir}/output"],
321
  capture_output=True,
322
  )
323
  if result.returncode != 0:
324
+ print(f"Compilation failed: {result.stderr.decode('utf-8')}")
325
  return {
326
+ "success": False,
327
  "error": "Compilation failed",
328
  "output": result.stderr.decode("utf-8"),
329
  }
330
  return {
331
  "success": True,
332
  "output": result.stdout.decode("utf-8"),
333
+ "project_dir": project_dir,
334
  }
335
 
336
  def search_library(
main.py CHANGED
@@ -127,21 +127,11 @@ async def interact_with_agent(
127
  yield messages, None, None, None
128
  for call in event.get_function_responses():
129
  if call.name == "compile_with_arduino" and call.response["success"]:
130
- temp = tempfile.gettempdir()
131
-
132
- temp_uuid = str(uuid4())
133
- temp = os.path.join(temp, f"{temp_uuid}.ino.elf")
134
-
135
-
136
- with open(temp, "wb") as f:
137
- with open(
138
- "/tmp/arduino_project/output/arduino_project.ino.elf", "rb"
139
- ) as f2:
140
- f.write(f2.read())
141
 
142
  yield messages, None, None, gr.DownloadButton(
143
  "Download ELF",
144
- temp,
145
  variant="primary",
146
  render=False,
147
  interactive=True,
 
127
  yield messages, None, None, None
128
  for call in event.get_function_responses():
129
  if call.name == "compile_with_arduino" and call.response["success"]:
130
+ path = call.response["project_dir"]
 
 
 
 
 
 
 
 
 
 
131
 
132
  yield messages, None, None, gr.DownloadButton(
133
  "Download ELF",
134
+ os.path.join(path, "output", "arduino_project.ino.elf"),
135
  variant="primary",
136
  render=False,
137
  interactive=True,
uv.lock CHANGED
The diff for this file is too large to render. See raw diff