Spaces:
Running
Running
File size: 9,087 Bytes
77932b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "7daa2ba7",
"metadata": {},
"outputs": [],
"source": [
"import gradio as gr\n",
"from openai import OpenAI\n",
"from dotenv import load_dotenv\n",
"import os "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7de6ebda",
"metadata": {},
"outputs": [],
"source": [
"\n",
"projects = [\n",
" {\"image\": \"projects_images/s_up.jpeg\", \"title\": \"Ai Recommendation System\"},\n",
" {\"image\": \"projects_images/llm.jpeg\", \"title\": \"LLM Automation\"},\n",
" {\"image\": \"projects_images/bi.png\", \"title\": \"BI\"},\n",
" {\"image\": \"projects_images/robot.png\", \"title\": \"Robot Arm Control With Ros Python and AI \"},\n",
"]\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8e38d667",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"load_dotenv()\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7708eac4",
"metadata": {},
"outputs": [],
"source": [
"with open(\"cv/me.txt\", \"r\") as f: \n",
" cv_text = f.read()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "34dc7b6a",
"metadata": {},
"outputs": [],
"source": [
"client = OpenAI()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "efd52cc5",
"metadata": {},
"outputs": [],
"source": [
"system_prompt = f\"\"\"\n",
"Your name is Alexander.You are acting as Alexander Todorov. You will answer questions related to your career, skills, work experience, and education. \\\n",
"Questions will be asked by visitors, headhunters, or recruiters about potential job opportunities. \\\n",
"Respond professionally and use professional language. \\\n",
"Answer only questions that are directly related to your CV. If you do not find the answer in your CV, respond with: \\\n",
"\"I can only answer questions about my CV.\"\n",
"\n",
"CV: {cv_text}\n",
"With this context, please chat with the user, always staying in character as Alexander Todorov.\n",
"\"\"\"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "5e16df81",
"metadata": {},
"outputs": [],
"source": [
"def chat(message,history):\n",
" messages = [{\"role\":\"system\", \"content\":system_prompt}] + history + [{\"role\":\"user\", \"content\":message}]\n",
" response = client.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n",
" return response.choices[0].message.content"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ad803f77",
"metadata": {},
"outputs": [],
"source": [
"# --------- CHAT FUNCTION FOR THE AGENT ----------\n",
"def chat_with_agent(message, history):\n",
" # Call your Agent here (OpenAI Agent, LangChain, etc.)\n",
" # For now return example text:\n",
" return f\"You said: {message}\""
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "f4807389",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7860\n",
"* To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"with gr.Blocks() as ui:\n",
"\n",
"\n",
" # name and job title \n",
" with gr.Row():\n",
" with gr.Column(scale=1):\n",
" gr.Markdown('<div style=\"font-size:36px; font-weight:bold;\">Alexander Todorov</div>')\n",
"\n",
" with gr.Column(scale=4): \n",
" gr.Markdown(\"\"\"\n",
" <a href=\"https://www.linkedin.com/in/alexander-t-50864a139\" target=\"_blank\">\n",
" <img src=\"https://cdn-icons-png.flaticon.com/512/174/174857.png\" \n",
" alt=\"LinkedIn\" style=\"width:32px; height:32px;\"/>\n",
" </a>\n",
" \"\"\")\n",
"\n",
"\n",
" # gr.Markdown(f'<p style=\"color:#9b9b9b; margin-bottom:0;font-size:20px;\">Software Engineer & Data Scientist</p>',\n",
" # elem_id=\"job-title-light\")\n",
"\n",
" # LinkedIn icon with link\n",
" \n",
" \n",
"\n",
" # ********************************************************************************************************* \n",
" \n",
" with gr.Row():\n",
" with gr.Column(scale=1): # 1 part\n",
" gr.Image(\"cv/avatar.jpeg\", \n",
" type=\"pil\", \n",
" show_label=False, \n",
" height=150, \n",
" interactive=False, \n",
" container=False, \n",
" buttons=[['download', 'share', 'fullscreen']])\n",
"\n",
" # Right column 75% width\n",
" with gr.Column(scale=3): # 3 parts\n",
" gr.Markdown(\"\"\"\n",
" <div style=\"width:50%\">\n",
" <p style=\"color:#9b9b9b; margin-bottom:0;font-size:20px;\">\n",
" Software and Data Engineer with over five years of experience delivering intelligent, \n",
" user-focused AI solutions and driving automation and innovation in complex environments.\n",
" </p>\n",
" </div>\n",
" \"\"\")\n",
" \n",
"\n",
" # ******************************************************************************************************************\n",
" # Chatbot \n",
" gr.Markdown(f'<p style=\"font-size:28px;font-weight:bold;\"> Chat with Me About My CV</p>',\n",
" elem_id=\"job-title-light\")\n",
" gr.Markdown('<hr style=\"border:1px solid grey;\">', elem_id=\"custom_divider\")\n",
" chatbot = gr.Chatbot(placeholder=\"<strong>Interactive CV Guide</strong><br>Ask Me Anything\", height=300)\n",
" chat_interface = gr.ChatInterface(fn=chat, chatbot=chatbot)\n",
" gr.Markdown('<hr style=\"border: 1px solid #d3d3d3; margin-top:12px; margin-bottom:12px;\">')\n",
" # horizontal line\n",
"\n",
" \n",
" # ****************************************************************************************************************\n",
" # Projects \n",
" gr.Markdown(f'<p style=\"font-size:28px;font-weight:bold;\"> Examples of My Work</p>',\n",
" elem_id=\"job-title-light\")\n",
" gr.Markdown('<hr style=\"border:1px solid grey;\">', elem_id=\"custom_divider\")\n",
" \n",
" # Projects row \n",
" with gr.Row():\n",
" for project in projects:\n",
" with gr.Column(): # equal width for each project\n",
" # Project image (disable download)\n",
" gr.Image(project[\"image\"], \n",
" type=\"pil\", \n",
" show_label=False, \n",
" interactive=False, \n",
" height=200, width=350,\n",
" buttons=[['download', 'share', 'fullscreen']])\n",
" # Project title / text\n",
" gr.Markdown(f\"<div style='text-align:center; font-size:16px; margin-top:4px;'>{project['title']}</div>\")\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"ui.launch()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "769f66e6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|