Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Programming question]: Drawing SVG files #184

Open
haesleinhuepf opened this issue Dec 26, 2024 · 3 comments
Open

[Programming question]: Drawing SVG files #184

haesleinhuepf opened this issue Dec 26, 2024 · 3 comments

Comments

@haesleinhuepf
Copy link
Owner

I would like to program a Python function draw_vector_graphics(prompt:str, filename:str, prompt_function:callable) that generates SVG graphics using a prompt to a language model. Assume prompt_function(prompt:str)-> can generate SVG graphic file contents. Now write the implementation of draw_vector_graphics consisting of:

  • define a detailed prompt that asks for a SVG graphics. The variable prompt is a high-level description of what should be drawn. You just need to write around that it should be a SVG graphics and how to do this.
  • Save the resulting file to disk.

git-bob think about how to do this.

Copy link
Contributor

This message was generated by git-bob (version: 0.16.1dev, model: claude-3-5-sonnet-20241022, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

Hi there! Let me help you with implementing the draw_vector_graphics function. Here's a Jupyter notebook with the implementation:

def draw_vector_graphics(prompt: str, filename: str, prompt_function: callable):
    # Create a detailed prompt that asks for SVG graphics
    detailed_prompt = f"""Please create an SVG graphic that represents: {prompt}
    
    The response should:
    * Be a valid SVG file
    * Start with <?xml version="1.0" encoding="UTF-8"?>
    * Contain an <svg> element with appropriate width, height and viewBox
    * Use basic SVG elements like rect, circle, path, text etc.
    * Only contain the SVG code, no explanation
    """
    
    # Get the SVG content using the provided prompt function
    svg_content = prompt_function(detailed_prompt)
    
    # Save the SVG content to the specified file
    with open(filename, 'w', encoding='utf-8') as f:
        f.write(svg_content)

This implementation:

  1. Creates a detailed prompt requesting SVG graphics
  2. Uses the provided prompt_function to generate SVG content
  3. Saves the content to the specified filename

You can use it like:

# Example usage
prompt = "a cat sitting on a windowsill"
draw_vector_graphics(prompt, "cat.svg", your_prompt_function)

The actual SVG generation depends on your prompt_function implementation which could use any language model API.

@haesleinhuepf
Copy link
Owner Author

Fantastic! git-bob try this out!

Copy link
Contributor

This message was generated by git-bob (version: 0.16.1dev, model: claude-3-5-sonnet-20241022, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

I implemented a solution for generating SVG graphics using language model prompts. I created a Python function draw_vector_graphics that takes a prompt describing what to draw, a filename to save the result, and a prompt function that generates SVG content. To demonstrate the functionality, I created a notebook with a mock prompt function that generates a simple circle SVG, and I included both the implementation and an example usage. The function constructs a detailed prompt requesting specific SVG formatting and saves the generated content to a file.

  • circle.svg Added a sample SVG file containing a simple circle graphic generated by the notebook.
  • svg_graphics_generator.ipynb Created a new Jupyter notebook implementing the SVG graphics generator function with example usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant