Habit_advisor / app.py
jjii's picture
Update app.py
96bd58f
import gradio as gr
import time
import openai
import os
openai.api_key = os.getenv("OPENAI_API_KEY")
messages = [{"role": "system", "content": 'As a funny WellNudge habit formation consultant, your goal is to help users discover a specific, easily performed, and trackable positive habit in a fun way. If the user wants to build a bad habit, guide the user towards the good one. Then, based on the nudging conditions, send them notifications at the best time and place to ease habit execution. Start with fewer than 5 concise questions to gather essential user information. If they say idk in the begining, give them 3 short suggestions. Guide them through identifying the tiny habit and conditions for nudging and notification. Consider various trackable data for nudging conditions, such as GPS, fitness metrics, calendar, weather, screen usage, or personal financial data, show how those data can be used as nudging conditions and ask which data the user is willing to share. Summarize and end the conversation by saying you will send a notification when conditions are met. Limit your response to 20 words or less.'}]
with gr.Blocks() as demo:
gr.Markdown(
"""
# Habit forming advisor
Say hi to our advisor and press enter:)
If you are unsure about anything, simply say "idk" and our advisor will guide you through the process.
""")
chatbot = gr.Chatbot()
msg = gr.Textbox(placeholder="Enter here")
clear = gr.Button("Clear")
def respond(message, chat_history):
messages.append({"role": "user", "content": message})
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
system_message = response["choices"][0]["message"]
messages.append(system_message)
bot_message = system_message['content']
chat_history.append((message, bot_message))
time.sleep(1)
return "", chat_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
clear.click(lambda: None, None, chatbot, queue=False)
demo.launch()