LuxOAI commited on
Commit
5641d8c
1 Parent(s): 50305c1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ import json
4
+
5
+ openai.api_key = "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"
6
+
7
+ def save_conversation():
8
+ with open('conversation.json', 'w') as f:
9
+ json.dump(messages, f)
10
+
11
+ def load_conversation():
12
+ try:
13
+ with open('conversation.json', 'r') as f:
14
+ return json.load(f)
15
+ except FileNotFoundError:
16
+ return []
17
+
18
+ messages = load_conversation()
19
+
20
+ if not messages:
21
+ messages.append({"role": "system", "content": "You are a knowledgeable assistant specialized in recruiting and hiring, and familiar with ADP Workforce Now Recruitment and various hiring and CRM tools."})
22
+
23
+ def CustomChatGPT(user_input):
24
+ messages.append({"role": "user", "content": user_input})
25
+
26
+ # Ensure the conversation fits within the model's maximum token limit
27
+ conversation = messages[-4096:]
28
+
29
+ try:
30
+ response = openai.ChatCompletion.create(
31
+ model="gpt-3.5-turbo",
32
+ messages=conversation,
33
+ max_tokens=1000,
34
+ temperature=0.7)
35
+ except openai.api_resources.request_error.RequestError as e:
36
+ print(f"Received error from OpenAI: {e}")
37
+ return "I'm sorry, but I'm unable to generate a response at this time."
38
+
39
+ ChatGPT_reply = response["choices"][0]["message"]["content"]
40
+ messages.append({"role": "assistant", "content": ChatGPT_reply})
41
+
42
+ save_conversation()
43
+
44
+ return ChatGPT_reply
45
+
46
+ interface = gr.Interface(fn=CustomChatGPT,
47
+ inputs="textbox",
48
+ outputs="textbox",
49
+ title="VIP-GPT",
50
+ description="Chat with a specialized assistant that can answer questions about recruiting, hiring, and various HR and CRM tools. Developed by A. Leschik.")
51
+
52
+ interface.launch()