diff --git a/SDXL_prompts/1.in b/SDXL_prompts/1.in new file mode 100644 index 0000000..6a701f5 --- /dev/null +++ b/SDXL_prompts/1.in @@ -0,0 +1 @@ +Soft Pink Roses \ No newline at end of file diff --git a/SDXL_prompts/1.out b/SDXL_prompts/1.out new file mode 100644 index 0000000..57b6591 --- /dev/null +++ b/SDXL_prompts/1.out @@ -0,0 +1 @@ +Soft pink roses, white Chinese peony, tiny apple blossom flowers, eucalyptus leaves, twigs of cranberries, twigs of copper pepper berries all arrangement into a cute beautiful flowers arrangement on a pink nickel mug. The mug is sitting on a thick white book with golden cover image design. Sunny, bright image. Ad copy, huge copy space on top of the image, negative space, hd, 8k, blurry dreamy background, beautiful pictures. Product \ No newline at end of file diff --git a/SDXL_prompts/2.in b/SDXL_prompts/2.in new file mode 100644 index 0000000..3de36af --- /dev/null +++ b/SDXL_prompts/2.in @@ -0,0 +1 @@ +Happy Dog \ No newline at end of file diff --git a/SDXL_prompts/2.out b/SDXL_prompts/2.out new file mode 100644 index 0000000..120b98f --- /dev/null +++ b/SDXL_prompts/2.out @@ -0,0 +1 @@ +a realistic happy dog ​​playing in the grass \ No newline at end of file diff --git a/SDXL_prompts/3.in b/SDXL_prompts/3.in new file mode 100644 index 0000000..98080fd --- /dev/null +++ b/SDXL_prompts/3.in @@ -0,0 +1 @@ +Gas Station \ No newline at end of file diff --git a/SDXL_prompts/3.out b/SDXL_prompts/3.out new file mode 100644 index 0000000..c722af1 --- /dev/null +++ b/SDXL_prompts/3.out @@ -0,0 +1,3 @@ +ours en peluche jaune , a restaurant is lit up at night on a rainy day, “gas station photography, cgsociety ), sad cop looking at a, by Nōami, picture of a loft in morning, dark ominous mood, petrol energy, a quaint, photo realistic symmetrical, drive out, pouring, terminal dark + +Style: Cinematic \ No newline at end of file diff --git a/SDXL_prompts/4.in b/SDXL_prompts/4.in new file mode 100644 index 0000000..9fb2d55 --- /dev/null +++ b/SDXL_prompts/4.in @@ -0,0 +1 @@ +Off Road Track \ No newline at end of file diff --git a/SDXL_prompts/4.out b/SDXL_prompts/4.out new file mode 100644 index 0000000..008cb91 --- /dev/null +++ b/SDXL_prompts/4.out @@ -0,0 +1,3 @@ +Prompt: A highly photorealistic image of a off road race track, complete with precise replicas of the world’s most iconic heavy noun, captured at the moment of a sharp turn, with smoke and sparks flying from under the wheels and the noun drifting around the bend. The image captures the excitement of the moment, with happy and noisy fans cheering and waving in the background. (The image is depicted at dusk, with the headlights + +Style: Photographic \ No newline at end of file diff --git a/SDXL_prompts/5.in b/SDXL_prompts/5.in new file mode 100644 index 0000000..80e7564 --- /dev/null +++ b/SDXL_prompts/5.in @@ -0,0 +1 @@ +Grapes \ No newline at end of file diff --git a/SDXL_prompts/5.out b/SDXL_prompts/5.out new file mode 100644 index 0000000..4520dc5 --- /dev/null +++ b/SDXL_prompts/5.out @@ -0,0 +1,3 @@ +Prompt: Powerful liquid explosion, Green grapes, Green background, Commercial photography, A bright environment, Studio lighting, OC rendering, Solid color isolated platform, Professional photography, Color classification, Super detail + +Style: Photographic \ No newline at end of file diff --git a/SDXL_prompts/6.in b/SDXL_prompts/6.in new file mode 100644 index 0000000..c095890 --- /dev/null +++ b/SDXL_prompts/6.in @@ -0,0 +1 @@ +Astronaut \ No newline at end of file diff --git a/SDXL_prompts/6.out b/SDXL_prompts/6.out new file mode 100644 index 0000000..20ca734 --- /dev/null +++ b/SDXL_prompts/6.out @@ -0,0 +1 @@ +Prompt: Astronaut on Mars During sunset \ No newline at end of file diff --git a/SDXL_prompts/7.in b/SDXL_prompts/7.in new file mode 100644 index 0000000..37ca1f3 --- /dev/null +++ b/SDXL_prompts/7.in @@ -0,0 +1 @@ +Locomotive \ No newline at end of file diff --git a/SDXL_prompts/7.out b/SDXL_prompts/7.out new file mode 100644 index 0000000..1920469 --- /dev/null +++ b/SDXL_prompts/7.out @@ -0,0 +1,6 @@ +Prompt: A cybernatic locomotive on rainy day from the parallel universe +Noise: 50% +Style realistic +Strength 6.0 + +Negative: Bad quality, bad detail, blurry-image, jpeg artifacts, bad contrast, bad anatomy, duplicate, watermark, extra detail, chaotic distribution of objects, distortion, bad detail facial details \ No newline at end of file diff --git a/main.ipynb b/main.ipynb deleted file mode 100644 index 1748103..0000000 --- a/main.ipynb +++ /dev/null @@ -1,112 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import torch\n", - "from transformers import AutoModelForCausalLM, AutoTokenizer\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "tokenizer = AutoTokenizer.from_pretrained(\"cerebras/btlm-3b-8k-base\")\n", - "model = AutoModelForCausalLM.from_pretrained(\"cerebras/btlm-3b-8k-base\", trust_remote_code=True, torch_dtype=\"auto\").to(\"cuda\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "prompt = \"\"\"SYSTEM: You are an agent tasked with creating better, more descriptive image prompts that result in higher quality outputs. You are given a user prompt, and determine how, if it all, to change the users image. Do you understand?\n", - "AGENT: Yes, I understand.\n", - "SYSTEM: Great. Below there will be a set of examples. For each example, you will be given the users prompt and the expected output. You will be then given a new user prompt and have to generate a new output. Do not output anything beyond the prompt. Do you understand?\n", - "AGENT: Yes.\n", - "SYSTEM: Another rule, do not list numbers in your response.\n", - "AGENT: Yes, I understand.\n", - "\n", - "PROMPT: A picture of a cat.\n", - "AGENT: masterpiece:2, Profession Photograph, A cat sitting on a chair, Orange, White whiskers\n", - "\n", - "PROMPT: The beach\n", - "AGENT: masterpiece:3, A beautiful beach, Palm trees, blue sky, white clouds, clear sky\n", - "\n", - "PROMPT: A picture of a dog.\n", - "AGENT:\"\"\"\n", - "# Change the last prompt to whatever you want to test\n", - "inputs = tokenizer(prompt, return_tensors=\"pt\").to(\"cuda\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Generate text using the model\n", - "outputs = model.generate(\n", - " **inputs,\n", - " num_beams=5,\n", - " max_new_tokens=50,\n", - " early_stopping=True,\n", - " no_repeat_ngram_size=2,\n", - " # use random seed\n", - " top_k=10,\n", - " top_p=0.9,\n", - " temperature=0.9,\n", - " do_sample=True,\n", - ")\n", - "# Convert the generated token IDs back to text\n", - "generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)\n", - "print(generated_text)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def filter_result(result):\n", - " result = result.replace(\"\\n\", \" \")\n", - " result = result[result.rfind(\"AGENT:\") + 7:]\n", - " result = result.split(\" \")[0]\n", - " result = result.split(\"```\")[0]\n", - " result = result.strip()\n", - " return result \n", - "\n", - "print(filter_result(generated_text[0]))\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "base", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.9" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/main.py b/main.py new file mode 100644 index 0000000..f147ea9 --- /dev/null +++ b/main.py @@ -0,0 +1,83 @@ +import torch +from transformers import AutoModelForCausalLM, AutoTokenizer +import os + +def filter_result(result) -> str: + result = result.replace("\n", " ") + result = result[result.rfind("AGENT:") + 7:] + result = result.split(" ")[0] + result = result.split("```")[0] + result = result.strip() + return result + +def read_sample_prompts(path: str) -> str: + output = "" + + # Sort files by their name to ensure they are processed in order + files = sorted(os.listdir(path)) + + # Extract and pair '.in' and '.out' files + input_files = [f for f in files if f.endswith('.in')] + output_files = [f for f in files if f.endswith('.out')] + + # Ensure each input file has a corresponding output file + if len(input_files) != len(output_files): + print("Mismatch between the number of input and output files!") + else: + for idx, (in_file, out_file) in enumerate(zip(input_files, output_files)): + # Read input file + with open(os.path.join(path, in_file), 'r') as f: + prompt = f.read().strip() + + # Read output file + with open(os.path.join(path, out_file), 'r') as f: + agent_response = f.read().strip() + + # Append to the output string in the desired format + output += f"PROMPT: {prompt}\n" + output += f"AGENT: masterpiece:{idx+1}, {agent_response}\n\n" + + return output + + +def main(prompt_in: str) -> str: + tokenizer = AutoTokenizer.from_pretrained("cerebras/btlm-3b-8k-base") + model = AutoModelForCausalLM.from_pretrained("cerebras/btlm-3b-8k-base", trust_remote_code=True, torch_dtype="auto").to("cuda") + + sample_prompts = read_sample_prompts('SDXL_prompts') + prompt = f"""SYSTEM: You are an agent tasked with creating better, more descriptive image prompts that result in higher quality outputs. You are given a user prompt, and determine how, if it all, to change the users image. Do you understand? +AGENT: Yes, I understand. +SYSTEM: Great. Below there will be a set of examples. For each example, you will be given the users prompt and the expected output. You will be then given a new user prompt and have to generate a new output. Do not output anything beyond the prompt. Do you understand? +AGENT: Yes. +SYSTEM: Another rule, do not list numbers in your response. +AGENT: Yes, I understand. + +{sample_prompts} + +PROMPT: {prompt_in} +AGENT:""" + + # Change the last prompt to whatever you want to test + inputs = tokenizer(prompt, return_tensors="pt").to("cuda") + + + # Generate text using the model + outputs = model.generate( + **inputs, + num_beams=5, + max_new_tokens=50, + early_stopping=True, + no_repeat_ngram_size=2, + # use random seed + top_k=10, + top_p=0.9, + temperature=0.9, + do_sample=True, + ) + # Convert the generated token IDs back to text + generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True) + return generated_text[0] + +if __name__ == "__main__": + edited = main("A picture of a dog") + print(filter_result(edited)) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 39dab0f..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -torch -transformers \ No newline at end of file