{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"},{"sourceId":16017,"databundleVersionId":708189,"sourceType":"competition"},{"sourceId":8731431,"sourceType":"datasetVersion","datasetId":5240893},{"sourceId":73454105,"sourceType":"kernelVersion"}],"dockerImageVersionId":30733,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install diffusers","metadata":{"execution":{"iopub.status.busy":"2024-06-19T17:21:29.283054Z","iopub.execute_input":"2024-06-19T17:21:29.283444Z","iopub.status.idle":"2024-06-19T17:21:41.825858Z","shell.execute_reply.started":"2024-06-19T17:21:29.283414Z","shell.execute_reply":"2024-06-19T17:21:41.824847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from diffusers import StableDiffusionPipeline\nimport torch\n\nmodel_id = \"dreamlike-art/dreamlike-diffusion-1.0\"\npipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)\npipe = pipe.to(\"cuda\")\n\nprompt = \"dreamlikeart, a grungy woman with rainbow hair, travelling between dimensions, dynamic pose, happy, soft eyes and narrow chin, extreme bokeh, dainty figure, long hair straight down, torn kawaii shirt and baggy jeans, In style of by Jordan Grimmer and greg rutkowski, crisp lines and color, complex background, particles, lines, wind, concept art, sharp focus, vivid colors\"\nimage = pipe(prompt).images[0]\n\nimage.save(\"./result.jpg\")","metadata":{"execution":{"iopub.status.busy":"2024-06-19T17:21:41.827752Z","iopub.execute_input":"2024-06-19T17:21:41.828061Z","iopub.status.idle":"2024-06-19T17:21:57.484272Z","shell.execute_reply.started":"2024-06-19T17:21:41.828032Z","shell.execute_reply":"2024-06-19T17:21:57.483232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image","metadata":{"execution":{"iopub.status.busy":"2024-06-19T17:21:57.485607Z","iopub.execute_input":"2024-06-19T17:21:57.486639Z","iopub.status.idle":"2024-06-19T17:21:57.756636Z","shell.execute_reply.started":"2024-06-19T17:21:57.486601Z","shell.execute_reply":"2024-06-19T17:21:57.755653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prompt = \"dreamlikeart, dog on the moon, crisp lines and color, complex background, particles, lines, wind, concept art, sharp focus, vivid colors\"\nimage = pipe(prompt).images[0]\n\nimage.save(\"./result0.jpg\")\nimage","metadata":{"execution":{"iopub.status.busy":"2024-06-19T17:21:57.758661Z","iopub.execute_input":"2024-06-19T17:21:57.759008Z","iopub.status.idle":"2024-06-19T17:22:11.889072Z","shell.execute_reply.started":"2024-06-19T17:21:57.758977Z","shell.execute_reply":"2024-06-19T17:22:11.888186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prompt = \"dreamlikeart, dog on the moon, crisp lines and color, complex background, particles, lines, wind, concept art, sharp focus, vivid colors\"\nimage = pipe(prompt).images[0]\n\nimage.save(\"./result0.jpg\")\nimage","metadata":{"execution":{"iopub.status.busy":"2024-06-19T16:08:13.941678Z","iopub.execute_input":"2024-06-19T16:08:13.941976Z","iopub.status.idle":"2024-06-19T16:08:28.068256Z","shell.execute_reply.started":"2024-06-19T16:08:13.941951Z","shell.execute_reply":"2024-06-19T16:08:28.067246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"prompt = \"dreamlikeart, robot city, complex background, particles, lines, wind, concept art, sharp focus, vivid colors\"\nimage = pipe(prompt).images[0]\n\nimage.save(\"./result1.jpg\")\nimage","metadata":{"execution":{"iopub.status.busy":"2024-06-19T17:31:25.879629Z","iopub.execute_input":"2024-06-19T17:31:25.879985Z","iopub.status.idle":"2024-06-19T17:31:40.015080Z","shell.execute_reply.started":"2024-06-19T17:31:25.879955Z","shell.execute_reply":"2024-06-19T17:31:40.014144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nfrom PIL import Image\nfrom transformers import CLIPProcessor, CLIPModel\n\n# Load Dreamlike Diffusion model (pseudo-code, replace with actual loading method)\n# model = load_model(\"dreamlike-art/dreamlike-diffusion-1.0\")\n# prompt = \"A beautiful painting of a futuristic city\"\n# generated_image = model.generate(prompt)\n\n# For demonstration, we use a placeholder image path and prompt\nimage_path = \"/kaggle/working/result1.jpg\"\nprompt = \"dreamlikeart, robot city, complex background, particles, lines, wind, concept art, sharp focus, vivid colors\"\n\n# Load CLIP model and processor\ndevice = \"cuda\" if torch.cuda.is_available() else \"cpu\"\nclip_model = CLIPModel.from_pretrained(\"openai/clip-vit-base-patch32\").to(device)\nprocessor = CLIPProcessor.from_pretrained(\"openai/clip-vit-base-patch32\")\n\n# Preprocess image and text\nimage = Image.open(image_path)\ninputs = processor(text=[prompt], images=image, return_tensors=\"pt\", padding=True).to(device)\n\n# Compute CLIP score\nwith torch.no_grad():\n    outputs = clip_model(**inputs)\n    logits_per_image = outputs.logits_per_image\n    clip_score = logits_per_image.item()\n\nprint(f\"CLIP Score: {clip_score}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-06-19T17:31:40.016727Z","iopub.execute_input":"2024-06-19T17:31:40.017044Z","iopub.status.idle":"2024-06-19T17:31:41.184733Z","shell.execute_reply.started":"2024-06-19T17:31:40.017015Z","shell.execute_reply":"2024-06-19T17:31:41.183756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}