| | import gradio as gr |
| | import openai |
| | import os |
| | from openai import OpenAI |
| |
|
| | client = OpenAI() |
| |
|
| | |
| | openai.api_key = os.getenv("OPENAI_API_KEY") |
| |
|
| | |
| | def load_cv(): |
| | with open("templated_CV.txt", 'r') as file: |
| | return file.read() |
| |
|
| | |
| | cv_text = load_cv() |
| |
|
| | |
| | history = [] |
| |
|
| | def chat_with_ai(user_input): |
| | global history |
| | |
| | |
| | history.append({"role": "user", "content": user_input}) |
| |
|
| | |
| | if len(history) > 20: |
| | history = history[-20:] |
| |
|
| | |
| | messages = [ |
| | {"role": "system", "content": f"Assume you are Karthik Raja, and this the contents of your coverletter: {cv_text}. Assuming you are KarthikRaja, answer the questions accordingly. PLease make sure to not add more info other than that provided in the cover letter."}, |
| | ] + history |
| |
|
| | |
| | completion = client.chat.completions.create( |
| | model="gpt-3.5-turbo", |
| | messages=messages |
| | ) |
| | |
| | assistant_message = completion.choices[0].message |
| | |
| | history.append(assistant_message) |
| |
|
| | return assistant_message.content |
| |
|
| | def main(user_input): |
| | response = chat_with_ai(user_input) |
| | return response |
| |
|
| | iface = gr.Interface( |
| | fn=main, |
| | inputs=gr.Textbox(label="Ask a question, that you would like to ask Karthik"), |
| | outputs="text", |
| | title="AI Clone", |
| | description="Interact with an AI clone for recruiting or for fun :)" |
| | ) |
| |
|
| | iface.launch() |
| |
|