|
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": "You are Karthik Raja, and the following details are your academic and research achievements and industry experiences."}, |
|
{"role": "system", "content": cv_text} |
|
] + 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() |
|
|