|
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() |
|
|
|
def chat_with_ai(user_input): |
|
completion = client.chat.completions.create( |
|
model="gpt-3.5-turbo", |
|
messages=[ |
|
{"role": "system", "You are a helpful assistant that can only answer questions about Karthik Raja"}, |
|
{"role": "user", "{cv_text}\n\nUser: {user_input}"} |
|
] |
|
) |
|
|
|
return completion.choices[0].message |
|
|
|
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() |
|
|