Spaces:
Build error
Build error
Update tasks/ref_in_gpt3.py
Browse files- tasks/ref_in_gpt3.py +13 -23
tasks/ref_in_gpt3.py
CHANGED
|
@@ -31,13 +31,14 @@ pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
|
| 31 |
).to("cuda")
|
| 32 |
|
| 33 |
prompts = []
|
| 34 |
-
prompts.append("remove the person, task: (referring editing), source: [person], target:<clean and empty scene
|
| 35 |
-
prompts.append("remove the person in the middle, task: (referring editing), source: [person in the middle], target:<clean and empty scene
|
| 36 |
-
prompts.append("remove the dog on the left side, task: (referring editing), source: [dog on the left side], target:<clean and empty scene
|
| 37 |
-
prompts.append("change the apple to a pear, task: (referring editing), source: [apple], target: <pear
|
| 38 |
-
prompts.append("change the red apple to a green one, task: (referring editing), source: [red apple], target: <green apple
|
| 39 |
-
prompts.append("
|
| 40 |
-
prompts.append("replace the
|
|
|
|
| 41 |
|
| 42 |
openai.api_type = "azure"
|
| 43 |
openai.api_base = "https://xdecoder.openai.azure.com/"
|
|
@@ -45,34 +46,23 @@ openai.api_version = "2022-12-01"
|
|
| 45 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 46 |
|
| 47 |
def get_gpt3_response(prompt):
|
| 48 |
-
# response = openai.Completion.create(
|
| 49 |
-
# model="text-davinci-003",
|
| 50 |
-
# prompt=prompt,
|
| 51 |
-
# temperature=0.7,
|
| 52 |
-
# max_tokens=128,
|
| 53 |
-
# top_p=1,
|
| 54 |
-
# frequency_penalty=0,
|
| 55 |
-
# presence_penalty=0
|
| 56 |
-
# )
|
| 57 |
-
|
| 58 |
response = openai.Completion.create(
|
| 59 |
engine="text001",
|
| 60 |
prompt=prompt,
|
| 61 |
-
temperature=
|
| 62 |
-
max_tokens=
|
| 63 |
-
top_p=
|
| 64 |
frequency_penalty=0,
|
| 65 |
presence_penalty=0,
|
| 66 |
-
best_of=1,
|
| 67 |
-
stop=None
|
| 68 |
)
|
| 69 |
|
| 70 |
return response
|
| 71 |
|
| 72 |
def referring_inpainting_gpt3(model, image, instruction, *args, **kwargs):
|
| 73 |
# convert instruction to source and target
|
|
|
|
| 74 |
print(instruction)
|
| 75 |
-
resp = get_gpt3_response(' '.join(prompts) + instruction + ',')
|
| 76 |
resp_text = resp['choices'][0]['text']
|
| 77 |
print(resp_text)
|
| 78 |
ref_text = resp_text[resp_text.find('[')+1:resp_text.find(']')]
|
|
|
|
| 31 |
).to("cuda")
|
| 32 |
|
| 33 |
prompts = []
|
| 34 |
+
prompts.append("instruction: remove the person, task: (referring editing), source: [person], target:<clean and empty scene>.")
|
| 35 |
+
prompts.append("instruction: remove the person in the middle, task: (referring editing), source: [person in the middle], target:<clean and empty scene>.")
|
| 36 |
+
prompts.append("instruction: remove the dog on the left side, task: (referring editing), source: [dog on the left side], target:<clean and empty scene>.")
|
| 37 |
+
prompts.append("instruction: change the apple to a pear, task: (referring editing), source: [apple], target: <pear>.")
|
| 38 |
+
prompts.append("instruction: change the red apple to a green one, task: (referring editing), source: [red apple], target: <green apple>.")
|
| 39 |
+
prompts.append("instruction: change the color of bird's feathers from white to blue, task: (referring editing), source: [white bird], target: <blue bird>.")
|
| 40 |
+
prompts.append("instruction: replace the dog with a cat, task: (referring editing), source: [dot], target: <cat>.")
|
| 41 |
+
prompts.append("instruction: replace the red apple with a green one, task: (referring editing), source: [red apple], target: <green apple>.")
|
| 42 |
|
| 43 |
openai.api_type = "azure"
|
| 44 |
openai.api_base = "https://xdecoder.openai.azure.com/"
|
|
|
|
| 46 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 47 |
|
| 48 |
def get_gpt3_response(prompt):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
response = openai.Completion.create(
|
| 50 |
engine="text001",
|
| 51 |
prompt=prompt,
|
| 52 |
+
temperature=0.7,
|
| 53 |
+
max_tokens=512,
|
| 54 |
+
top_p=1,
|
| 55 |
frequency_penalty=0,
|
| 56 |
presence_penalty=0,
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
return response
|
| 60 |
|
| 61 |
def referring_inpainting_gpt3(model, image, instruction, *args, **kwargs):
|
| 62 |
# convert instruction to source and target
|
| 63 |
+
instruction = instruction.replace('.', '')
|
| 64 |
print(instruction)
|
| 65 |
+
resp = get_gpt3_response(' '.join(prompts) + ' instruction: ' + instruction + ',')
|
| 66 |
resp_text = resp['choices'][0]['text']
|
| 67 |
print(resp_text)
|
| 68 |
ref_text = resp_text[resp_text.find('[')+1:resp_text.find(']')]
|