Anthony G commited on
Commit
7b10ac3
·
1 Parent(s): cb56211

added files

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +37 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from openai import OpenAI
3
+ from dotenv import load_dotenv
4
+ import gradio as gr
5
+
6
+ load_dotenv()
7
+ API_KEY = os.getenv("OPENAI_API_KEY")
8
+ openai = OpenAI(api_key=API_KEY)
9
+
10
+ create_msg = lambda x, y: {"role": x, "content": y}
11
+
12
+ SYSTEM_PROMPT = create_msg(
13
+ "system",
14
+ """You are a helpful mental health chatbot, please answer with care. If you don't know the answer, respond 'Sorry, I don't know the answer to this question.'. If the question is too complex, respond 'Kindly, consult a psychiatrist for further queries.'.""".strip(),
15
+ )
16
+
17
+
18
+ def predict(message, history):
19
+ history_openai_format = []
20
+ history_openai_format.append(SYSTEM_PROMPT)
21
+ for human, assistant in history:
22
+ history_openai_format.append({"role": "user", "content": human})
23
+ history_openai_format.append({"role": "assistant", "content": assistant})
24
+ history_openai_format.append({"role": "user", "content": message})
25
+
26
+ response = openai.chat.completions.create(
27
+ model="ft:gpt-3.5-turbo-0613:personal::8kBTG8eh", messages=history_openai_format, temperature=0.35, stream=True
28
+ )
29
+
30
+ partial_message = ""
31
+ for chunk in response:
32
+ if chunk.choices[0].delta.content is not None:
33
+ partial_message = partial_message + chunk.choices[0].delta.content
34
+ yield partial_message
35
+
36
+
37
+ gr.ChatInterface(fn=predict, title="Mental Health Chatbot - by Jayda Hunte").launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ openai
2
+ gradio
3
+ python-dotenv