/graphic_codex

Primary LanguageJupyter Notebook

Identify Adversarial Examples which Codex can understand but Dall-E cannot

Sources:

Program for code generation using openai, with correction

Add API key, generated from:https://beta.openai.com/account/api-keys in config file at ./config.json
{ "API Key": "" }

Code Usage

python src/main.py -h

usage: Text to code [-h] -m {edit,gen} -p PROMPT [PROMPT ...] [-t TEMPERATURE]
                    [-ec MAX_EDIT_COUNT] [-tok MAX_TOKENS] [-sc STARTER_CODE]

Given a prompt -> create/edit a code calling codex api

optional arguments:
  -h, --help            show this help message and exit
  -m {edit,gen}         Enter the mode to operate -> either generate or edit
  -p PROMPT [PROMPT ...]
                        Enter the Prompt
  -t TEMPERATURE        Enter the temperature
  -ec MAX_EDIT_COUNT    Enter the Max edit count
  -tok MAX_TOKENS       Enter the Max tokens count
  -sc STARTER_CODE      Enter the file location to edit

1. Code Generation

Prompting the program
python src/main.py -m gen -p <prompt>
Example:
python src/main.py -m gen -p program to print 7 rows of pascals triangle in python

The working code is written into out/sample1.py

generated code:

def pascal(n):
    for i in range(n):
        for j in range(i+1):
            print(binomialCoeff(i,j),end=" ")
        print()

def binomialCoeff(n,k):
    res=1
    if(k>n-k):
        k=n-k
    for i in range(k):
        res=res*(n-i)
        res=res//(i+1)
    return res

n=7
pascal(n)

Result from running the generated code:

1 
1 1 
1 2 1 
1 3 3 1 
1 4 6 4 1 
1 5 10 10 5 1 
1 6 15 20 15 6 1 

2. Modify existing code with Instruction

python src/main.py -m edit -p <Instruction> -sc <file location to initial code>
Example:
python src/main.py -m edit -p correct the code -sc path_to_py_file

The working code is written into out_edit/sample1.py

Input code from file

Print("Hello World ! )

Corrected Code

Print("Hello World ! ")

Output in out_edit/sample1.py

Hello World !