Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +56 -0
- config.py +1 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
|
4 |
+
openai.api_key = "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"
|
5 |
+
|
6 |
+
# A list to store the previous requests and responses
|
7 |
+
history = []
|
8 |
+
|
9 |
+
def chat(input):
|
10 |
+
if input == "":
|
11 |
+
return "Hello, welcome to my chatbot. How can I help you?"
|
12 |
+
elif input.lower().startswith("i need help motivating myself"):
|
13 |
+
# A request for a motivational coach
|
14 |
+
# Add the input to the history list
|
15 |
+
history.append(input)
|
16 |
+
# Create a prompt for ChatGPT that includes your instructions and the user's request
|
17 |
+
prompt = "I want you to act as a motivational coach. I will provide you with some information about someone's goals and challenges, and it will be your job to come up with strategies that can help this person achieve their goals. This could involve providing positive affirmations, giving helpful advice or suggesting activities they can do to reach their end goal.\n\n"
|
18 |
+
# Add the previous requests and responses from the history list
|
19 |
+
for i in range(len(history)):
|
20 |
+
prompt += f"Request {i+1}: {history[i]}\nResponse {i+1}: {history[i+1]}\n\n"
|
21 |
+
# Add the current request
|
22 |
+
prompt += f"Request {len(history)+1}: {input}\nResponse {len(history)+1}:"
|
23 |
+
# Call ChatGPT API with this prompt
|
24 |
+
response = openai.Completion.create(
|
25 |
+
engine="gpt-35-turbo",
|
26 |
+
prompt=prompt,
|
27 |
+
temperature=0.9,
|
28 |
+
max_tokens=150,
|
29 |
+
top_p=1,
|
30 |
+
frequency_penalty=0,
|
31 |
+
presence_penalty=0.6,
|
32 |
+
stop=["\n"]
|
33 |
+
)
|
34 |
+
# Get the text from ChatGPT response
|
35 |
+
text = response["choices"][0]["text"]
|
36 |
+
# Add this text to the history list
|
37 |
+
history.append(text)
|
38 |
+
return text
|
39 |
+
else:
|
40 |
+
# A normal chat message
|
41 |
+
# Clear the history list
|
42 |
+
history.clear()
|
43 |
+
response = openai.Completion.create(
|
44 |
+
engine="gpt-35-turbo",
|
45 |
+
prompt=input,
|
46 |
+
temperature=0.9,
|
47 |
+
max_tokens=150,
|
48 |
+
top_p=1,
|
49 |
+
frequency_penalty=0,
|
50 |
+
presence_penalty=0.6,
|
51 |
+
stop=["\n"]
|
52 |
+
)
|
53 |
+
return response["choices"][0]["text"]
|
54 |
+
|
55 |
+
iface = gr.Interface(chat, "textbox", "textbox", interpretation="default")
|
56 |
+
iface.launch()
|
config.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
OPENAI_API_KEY = "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"
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
openai==0.27.0
|