bstraehle Devin commited on
Commit
79218dd
·
1 Parent(s): f12aecf

Load the example output from example_output.md and drop sandbox file links

Browse files

The example output embeds the generated plot as base64 (~426 KB), which
is too large for a Space variable, so it now lives in the repo and the
OUTPUT variable is only a fallback. The model's [Download ...](sandbox:...)
links point into the code interpreter container and don't resolve in the
UI; they're removed since the images are already shown inline.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

Files changed (3) hide show
  1. app.py +4 -1
  2. example_output.md +0 -0
  3. multi_agent.py +4 -1
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import logging
2
  import os
3
  import sys
 
4
 
5
  import gradio as gr
6
 
@@ -8,6 +9,8 @@ from multi_agent import run_multi_agent
8
 
9
  LLM = "gpt-6.2-sol"
10
  CONCURRENCY_LIMIT = 8
 
 
11
 
12
  logging.basicConfig(stream=sys.stdout, level=logging.INFO)
13
  logger = logging.getLogger(__name__)
@@ -53,7 +56,7 @@ with gr.Blocks() as demo:
53
  clear_btn = gr.ClearButton(components=[openai_api_key, task])
54
  submit_btn = gr.Button("Submit", variant="primary")
55
  with gr.Column(scale=3):
56
- output = gr.Markdown(label="Output", value=os.environ.get("OUTPUT", ""), line_breaks=True, sanitize_html=False)
57
 
58
  clear_btn.add(output)
59
  submit_btn.click(fn=invoke, inputs=[openai_api_key, task], outputs=output, concurrency_limit=CONCURRENCY_LIMIT)
 
1
  import logging
2
  import os
3
  import sys
4
+ from pathlib import Path
5
 
6
  import gradio as gr
7
 
 
9
 
10
  LLM = "gpt-6.2-sol"
11
  CONCURRENCY_LIMIT = 8
12
+ # Example output shown before the first run; too large for a Space variable because of the inline image
13
+ EXAMPLE_OUTPUT = Path(__file__).with_name("example_output.md")
14
 
15
  logging.basicConfig(stream=sys.stdout, level=logging.INFO)
16
  logger = logging.getLogger(__name__)
 
56
  clear_btn = gr.ClearButton(components=[openai_api_key, task])
57
  submit_btn = gr.Button("Submit", variant="primary")
58
  with gr.Column(scale=3):
59
+ output = gr.Markdown(label="Output", value=EXAMPLE_OUTPUT.read_text(encoding="utf-8") if EXAMPLE_OUTPUT.exists() else os.environ.get("OUTPUT", ""), line_breaks=True, sanitize_html=False)
60
 
61
  clear_btn.add(output)
62
  submit_btn.click(fn=invoke, inputs=[openai_api_key, task], outputs=output, concurrency_limit=CONCURRENCY_LIMIT)
example_output.md ADDED
The diff for this file is too large to render. See raw diff
 
multi_agent.py CHANGED
@@ -1,5 +1,6 @@
1
  import base64
2
  import mimetypes
 
3
  from datetime import date
4
  from typing import Annotated
5
 
@@ -11,6 +12,8 @@ from pydantic import Field
11
 
12
  MAX_TOOL_ITERATIONS = 10
13
  IMAGE_EXTENSIONS = (".png", ".jpg", ".jpeg", ".gif", ".webp")
 
 
14
 
15
  INSTRUCTIONS = (
16
  "You are a Sr. Python Programmer, an expert in writing Pylint-compliant code. "
@@ -70,7 +73,7 @@ async def run_multi_agent(openai_api_key: str, model: str, task: str) -> str:
70
  if logs:
71
  transcript.append(f"```\n{logs}\n```")
72
  elif content.type == "text" and content.text:
73
- transcript.append(f"**Code Writer**\n{content.text}")
74
  for annotation in content.annotations or []:
75
  file_id, filename = annotation.get("file_id"), annotation.get("url") or ""
76
  container_id = (annotation.get("additional_properties") or {}).get("container_id")
 
1
  import base64
2
  import mimetypes
3
+ import re
4
  from datetime import date
5
  from typing import Annotated
6
 
 
12
 
13
  MAX_TOOL_ITERATIONS = 10
14
  IMAGE_EXTENSIONS = (".png", ".jpg", ".jpeg", ".gif", ".webp")
15
+ # Links to files in the code interpreter container don't resolve outside it; images are shown inline instead
16
+ SANDBOX_LINK = re.compile(r"\[[^\]]*\]\(sandbox:[^)]*\)\n?")
17
 
18
  INSTRUCTIONS = (
19
  "You are a Sr. Python Programmer, an expert in writing Pylint-compliant code. "
 
73
  if logs:
74
  transcript.append(f"```\n{logs}\n```")
75
  elif content.type == "text" and content.text:
76
+ transcript.append(f"**Code Writer**\n{SANDBOX_LINK.sub('', content.text).strip()}")
77
  for annotation in content.annotations or []:
78
  file_id, filename = annotation.get("file_id"), annotation.get("url") or ""
79
  container_id = (annotation.get("additional_properties") or {}).get("container_id")