from dotenv import load_dotenv from openai import OpenAI import json import os import requests from pypdf import PdfReader import gradio as gr import glob import random import threading import time import io import pathlib import base64 # Load environment variables from .env file load_dotenv(override=True) class AmitKumar: def __init__(self): # Initialize the OpenAI client for Gemini API calls google_api_key = os.getenv("GOOGLE_API_KEY") self.gemini = OpenAI(api_key=google_api_key, base_url="https://generativelanguage.googleapis.com/v1beta/openai/") self.model_name = "gemini-2.0-flash" # Your professional information self.name = "Amit Kumar" self.pdf_file = "me/amitcvprofile.pdf" # Updated PDF file name self.info = """ My name is Amit Kumar. I'm a Senior Test Engineer at HCLTech in Noida. I have extensive experience in manual and automation testing, with **3.5+ years in Selenium with Core Java**, **2+ years in Appium** for mobile automation, and **1+ years in API automation** using Rest Assured and Postman. My overall experience is **4 years and 9 months**. I am proficient in programming languages, including **Core Java** and **Python**. My professional expertise also includes **TestNG** and **BDD (Behavior-Driven Development)** with **Gherkin**. I'm an Agentic AI enthusiast with certifications. My professional expertise includes building automation frameworks from the ground up, managing CI/CD pipelines with Maven and Jenkins, and handling defect management. I'm comfortable working across Windows, Mac, and Linux operating systems. I am a native Hindi speaker and am professionally fluent in English. I love automation, and have hands on automation of web and mobile(android and ios application) I am currently working in HCLTech with 4+ year of experience. ## Additional Information for Recruiters: - **Expected Salary:** My expected salary is between 10 to 12 LPA. I prefer not to disclose my current salary. - **Notice Period:** My notice period is 2 months. I am open to discussing a buyout option if it is available. """ def system_prompt(self): """ Generates the system prompt to define the chatbot's persona and knowledge base. """ prompt = f""" You are Amit Kumar, a Senior Test Engineer. Your purpose is to answer questions from recruiters about your professional experience. Your responses must be based solely on the provided information below. Do not make up any details. Maintain a professional, knowledgeable, and confident tone. Be concise and direct in your answers. ## My Professional Profile: {self.info} ## Special Instruction: - If you are asked about messaging on WhatsApp, respond by saying "If you have my number, you can message me there." Do not state that you are an AI or that you cannot be messaged personally. - If you are asked if my resume is latest on Naukri or for a resume link, respond by saying "Yes, my resume is latest on Naukri, and the link is also available on my LinkedIn profile. If you can't find it, please feel free to email me at amitkumar1508.in@gmail.com." - If asked about willingness to relocate, say "Yes." - If asked about willingness to work in a night shift, say "Yes." Now, a recruiter will ask you questions. Please respond as Amit Kumar based on the provided profile. If a recruiter asks about something not mentioned in the profile (e.g., personal life, or a specific technology not listed), suggest they email me at amitkumar1508.in@gmail.com for more information. If you are asked to save or note something, say that you will note it down and inform Amit. """ return prompt def chat(self, message, history): """ Handles the chat conversation with the model. The chatbot will use the provided profile to answer questions. """ # Create the message history for the Gemini API call gemini_messages = [{"role": "system", "content": self.system_prompt()}] for user_msg, bot_msg in history: # Append user messages to the history gemini_messages.append({"role": "user", "content": user_msg}) # Append bot messages to the history if bot_msg: gemini_messages.append({"role": "assistant", "content": bot_msg}) # Add the new user message to the conversation history before making the API call gemini_messages.append({"role": "user", "content": message}) # Make the API call to Gemini response = self.gemini.chat.completions.create( model=self.model_name, messages=gemini_messages ) # Extract the content from the response return response.choices[0].message.content # Placeholder for a push notification function def push(text): """ Sends a push notification using the Pushover API. (Placeholder function, as environment variables are not available here) """ pushover_token = os.getenv("PUSHOVER_TOKEN") pushover_user = os.getenv("PUSHOVER_USER") if pushover_token and pushover_user: requests.post( "https://api.pushover.net/1/messages.json", data={ "token": pushover_token, "user": pushover_user, "message": text, } ) else: print(f"Push notification sent: {text}") # Create an instance of the AmitKumar class in the global scope # so it can be accessed by the get_agent_response function. amit = AmitKumar() # Gradio interface setup def get_agent_response(message, history): """ A wrapper function to get the chatbot's response for Gradio. """ # Send push notification for the user's message push(f"User message received: {message}") # Create an empty response for the user's message history.append((message, None)) # Yield the updated history so the user's message appears immediately yield "", history # Get the model's response response = amit.chat(message, history) # Update the last message with the model's response history[-1] = (message, response) # Send push notification for the agent's reply push(f"Agent replied: {response}") # Yield the final history yield "", history if __name__ == "__main__": # Define a helper function to copy text to clipboard js_copy_email = """ function(text) { navigator.clipboard.writeText(text); return 'Email copied to clipboard!'; } """ with gr.Blocks() as demo: # Chatbot header, now at the top of the full page with gr.Row(): with gr.Column(elem_id="contact-info"): # Use HTML to make the name larger and bolder gr.HTML("