|
import gradio as gr |
|
import time |
|
import openai |
|
import os |
|
openai.api_key = os.getenv("OPENAI_API_KEY") |
|
|
|
messages = [{"role": "system", "content": 'As a friendly and funny exam preparation productivity consultant, your goal is to help users discover a specific, easily performed, and trackable exam preparation productivity habit in a fun way. 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. Guide them through identifying the productivity 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. Tell user to leave their email below to subscribe and get informed when the budging app is finished. Limit your response to 20 words or less.'}] |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown( |
|
""" |
|
# Exam preparation 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() |