Merge pull request #649 from huiandjie/community-contributions-branch
Added my contributions to community-contributions
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
|
||||
# Enhanced Profile Picture
|
||||
Create a stylish profile picture by extracting all the companies you worked for and all the clients you serviced from your profile, and add these company/client logos to your profile picture after applying some Ghibili style.
|
||||
|
||||
## Contents
|
||||
|
||||
- `profile_with_company_logos.ipynb`: The notebook file with all code and explanations.
|
||||
- `my_profile.pdf`: Your profile in pdf format. (Please relace this file with your own profile)
|
||||
- `my_picture.jpg`: Your profile picture. (Please replace this with your own picture)
|
||||
- `ai_profile_picture.png`: The AI generated picture.
|
||||
|
||||
## How to Run
|
||||
|
||||
1. Add the GOOGLE_API_KEY.
|
||||
2. Run the jupyter notebook.
|
||||
|
||||
|
||||
### Author
|
||||
|
||||
Hui Wang
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
Binary file not shown.
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"from dotenv import load_dotenv\n",
|
||||
"from IPython.display import Markdown, display, update_display\n",
|
||||
"from google import genai\n",
|
||||
"from google.genai import types\n",
|
||||
"from PIL import Image\n",
|
||||
"from io import BytesIO\n",
|
||||
"import base64\n",
|
||||
"from PyPDF2 import PdfReader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {
|
||||
"id": "Jd_mMczWPcf-"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# prompt: get gemini api key and create a client connection to gemini\n",
|
||||
"\n",
|
||||
"# imports\n",
|
||||
"\n",
|
||||
"load_dotenv(override=True)\n",
|
||||
"google_api_key = os.getenv('GOOGLE_API_KEY')\n",
|
||||
"\n",
|
||||
"google = genai.Client(api_key=google_api_key)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {
|
||||
"id": "STKn3tGIVxOA"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def modifyImage(image, prompt):\n",
|
||||
" response = google.models.generate_content(\n",
|
||||
" model=\"gemini-2.0-flash-preview-image-generation\",\n",
|
||||
" contents=[prompt, image],\n",
|
||||
" config=types.GenerateContentConfig(\n",
|
||||
" response_modalities=['TEXT', 'IMAGE'],\n",
|
||||
" temperature=0.1\n",
|
||||
" )\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" for part in response.candidates[0].content.parts:\n",
|
||||
" if part.text is not None:\n",
|
||||
" print(part.text)\n",
|
||||
" elif part.inline_data is not None:\n",
|
||||
" image = Image.open(BytesIO(part.inline_data.data))\n",
|
||||
" #image.show()\n",
|
||||
" return image"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "06h-zRWtWL2J",
|
||||
"outputId": "e12b3b9a-4586-4cac-b3b9-1b5d6f27f708"
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"I will transform the photograph into a vibrant Ghibli-style illustration. The scene will depict a man in a blue striped shirt and light blue shorts standing on a balcony with a glass railing. Behind him, the iconic Hollywood sign will be visible on a sun-drenched, grassy hillside under a clear blue sky, rendered with the characteristic soft lines and lush colors of Studio Ghibli animation.\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"styled_image = modifyImage(Image.open('my_picture.jpg'), 'convert the attached images to a Ghibli art work.')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"metadata": {
|
||||
"id": "mR8MoSimZ14L"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def read_pdf(file_name):\n",
|
||||
" file = open(file_name, \"rb\")\n",
|
||||
" bin = file.read()\n",
|
||||
" reader = PdfReader(BytesIO(bin))\n",
|
||||
"\n",
|
||||
" text = \"\"\n",
|
||||
" for page in reader.pages:\n",
|
||||
" text += page.extract_text()\n",
|
||||
" return text\n",
|
||||
" \n",
|
||||
"def find_companies(text):\n",
|
||||
" response = google.models.generate_content(\n",
|
||||
" model=\"gemini-2.0-flash\",\n",
|
||||
" config=types.GenerateContentConfig(\n",
|
||||
" system_instruction=\"You are a career assistant.\"),\n",
|
||||
" contents=('From the following text, please identity the company names I worked at or served as client. Please only return the company names, with each company name on a new line, no other text: \\n' + text)\n",
|
||||
" )\n",
|
||||
" return response.candidates[0].content.parts[0].text"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"metadata": {
|
||||
"id": "uZopM8pObBIB"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"pdf_text = read_pdf('my_profile.pdf')\n",
|
||||
"company_response = find_companies(pdf_text)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "kKoneJrjegUu",
|
||||
"outputId": "96f601f5-dec5-424f-b8ad-34c019091395"
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"I will add the specified company logos as subtle elements in the background of the image, ensuring each logo appears only once and does not distract from the main subject.\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"final_image = modifyImage(styled_image, 'Please add the following company logos to the background, make sure only add each logo once:\\n' + company_response)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"final_image.save('ai_profile_picture.png')"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"provenance": []
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "llms",
|
||||
"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.11.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
||||
Reference in New Issue
Block a user