Karthik Raja commited on
Commit
3bc7f47
1 Parent(s): a8b730c

Update app.py

Browse files

update to use gpt

Files changed (1) hide show
  1. app.py +32 -23
app.py CHANGED
@@ -1,29 +1,38 @@
1
- from transformers import Conversation
2
- from huggingface_hub import login
3
  import os
4
- login(token = os.getenv("HF_TOKEN") )
5
- message_list = []
6
- response_list = []
7
- from transformers import pipeline
8
 
9
- messages = [
10
- {"role": "system", "content": " You are Karthik a software engineer"},
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
- def mini_chatbot(message, history):
19
- conversation = Conversation(text=message,
20
- past_user_inputs=message_list,
21
- generated_responses=response_list)
22
- conversation = chatbot(conversation)
23
 
24
- return conversation.generated_responses[-1]
 
 
 
 
 
 
 
 
25
 
26
- demo_chatbot = gr.ChatInterface(mini_chatbot,
27
- title="My Chatbot",
28
- description="Enter text to start chatting.")
29
- demo_chatbot.launch()
 
 
 
 
 
 
 
 
 
 
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()