Karthik Raja
commited on
Commit
•
3bc7f47
1
Parent(s):
a8b730c
Update app.py
Browse filesupdate to use gpt
app.py
CHANGED
@@ -1,29 +1,38 @@
|
|
1 |
-
|
2 |
-
|
3 |
import os
|
4 |
-
login(token = os.getenv("HF_TOKEN") )
|
5 |
-
message_list = []
|
6 |
-
response_list = []
|
7 |
-
from transformers import pipeline
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
{"role": "user", "content": "You are to impersonate as Karthik"},
|
12 |
-
{"role": "assistant", "content": "I am Karthik a software engineer"},
|
13 |
-
{"role": "user", "content": "Who are you? "},
|
14 |
-
]
|
15 |
-
chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3",max_new_tokens=5000)
|
16 |
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
past_user_inputs=message_list,
|
21 |
-
generated_responses=response_list)
|
22 |
-
conversation = chatbot(conversation)
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
import os
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
# Load your OpenAI API key from the environment variable
|
6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
# Read the static CV file
|
9 |
+
def load_cv():
|
10 |
+
with open("templated_CV.txt", 'r') as file:
|
11 |
+
return file.read()
|
12 |
|
13 |
+
# Extract information from the CV
|
14 |
+
cv_text = load_cv()
|
|
|
|
|
|
|
15 |
|
16 |
+
def chat_with_ai(user_input):
|
17 |
+
prompt = f"{cv_text}\n\nUser: {user_input}\nAI:"
|
18 |
+
response = openai.ChatCompletion.create(
|
19 |
+
model="gpt-3.5-turbo",
|
20 |
+
messages=[
|
21 |
+
{"role": "user", "content": prompt}
|
22 |
+
]
|
23 |
+
)
|
24 |
+
return response.choices[0].message['content']
|
25 |
|
26 |
+
def main(user_input):
|
27 |
+
response = chat_with_ai(user_input)
|
28 |
+
return response
|
29 |
+
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=main,
|
32 |
+
inputs=gr.Textbox(label="Ask a question, that you would like to ask Karthik"),
|
33 |
+
outputs="text",
|
34 |
+
title="AI Clone",
|
35 |
+
description="Interact with an AI clone for recruiting or for fun :) "
|
36 |
+
)
|
37 |
+
|
38 |
+
iface.launch()
|