Spaces:
Runtime error
Runtime error
File size: 7,613 Bytes
5f13555 4246ce0 848787c 98ee492 848787c 94b27ab 848787c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | import os
import gradio as gr
import openai as calmorah_ai
calmorah_ai.api_key = "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"
messages = [{"role": "system", "content": "Your name is Calmorah, a therapist. You are clever, non-judgmental, respectful, observant, helpful, empathetic."}]
marker = "Hello! I'm Calmorah, your companion for mental wellness. How can I help you feel better today?"
intro = [[None, "Hello! I'm Calmorah, your companion for mental wellness. How can I help you feel better today?"]]
logo_path = os.path.join(os.path.dirname(__file__), "images/logo.png")
def calmorahchatbot(user_input):
chat_history = [{"role": "assistant", "content": "Hello! I'm Calmorah, your companion for mental wellness. How can I assist you in feeling better today?"},
{"role": "user", "content": "Who created you?"},
{"role": "assistant", "content": "I was created by Cizonet Solutions, a tech company led by software developer Osaze Joseph Obayagbona. The team at Cizonet Solutions collaboratively "
"developed me as a tool to provide assistance and support related to mental health. My primary purpose is to "
"offer information on a wide range of mental health subjects, provide helpful coping "
"mechanisms, and lend a supportive ear to those who require it. Is there any way I could help "
"improve your mental well-being?"},
{"role": "user", "content": "What does Calmorah mean?"},
{"role": "assistant", "content": "My name Calmorah is a combination of two words, 'calm' and "
"'aura'. 'Calm' means a state of tranquility or peacefulness, "
"while 'Aura' refers to a distinctive quality or atmosphere that "
"surrounds a person or thing. Together, "
"Calmorah represents a space of tranquility "
"and calm where one can find solace and peace. "
"Well let's talk about you, how may I be of assistance in "
"improving your mental well-being today?"},
{"role": "user", "content": "When were you made"},
{"role": "assistant", "content": "I was created to help individuals in need of mental health support. "
"Specifically, I was founded in 2023 by a software developer Osaze Joseph Obayagbona "
"from Lagos, Nigeria, as part of the innovative work done by Cizonet Solutions. "
"Recognizing the importance of mental health, I was designed to provide support and "
"guidance to those who seek it. Is there anything specific that I can do to help you today?"},
{"role": "user", "content": "What is your purpose?"},
{"role": "assistant", "content": "My purpose is to support individuals in improving their "
"mental well-being. What can I help you with today?"},
{"role": "user", "content": user_input}]
response = calmorah_ai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=chat_history,
)
calmorah_reply = response["choices"][0]["message"]["content"]
chat_history.append({"role": "assistant", "content": calmorah_reply})
return calmorah_reply
def conversation_history(input, history):
history = history or []
if not input:
return history, history
output = calmorahchatbot(input)
history.append((input, output))
return history, history
theme = gr.themes.Default(primary_hue="purple", secondary_hue="purple").set(
loader_color="#4A395F",
slider_color="#4A395F",
)
interface = gr.Blocks(
title="New Chat - Calmorah",
theme=theme,
css="footer {visibility: hidden !important}"
".svelte-1p4r00v { "
"display: none;} "
"button.svelte-1p4r00v {"
"display: none;} "
"body { "
#"background-image: url('file=images/back.png'); "
"background-color: #4A395F; "
"background-repeat: no-repeat; "
"background-size: cover; "
"background-position: center center} "
".gradio-container { "
#"background-image: url('file=images/background.png'); "
"background-color: #4A395F; "
"background-repeat: no-repeat; "
"background-size: cover; "
"background-position: center} "
"#logo { "
"border-color: #4A395F;"
#"background-image: url('file=images/background.png'); "
"background-color: #4A395F; "
"background-repeat: no-repeat; "
"background-size: cover; "
"background-position: center} "
"#back {"
"display: inline-block; "
"border-color: none;"
"paddin g-right: 7%;} "
"#send {"
"background-color: transparent;"
"background: transparent;"
"border: none;"
"border-color: none;"
"display: block; "
"width: 7%; "
"height: 2.7em;"
"margin-top: 10px;"
"padding: 10px 15px;"
"font-size: 16px;"
"font-weight: bold;"
"color: #8770A4;"
"position: absolute;"
"right: 0.8px;"
"bottom: 11px} "
"#send:hover{"
"color: #37415A} "
"@media only screen and (min-width: 770px) and (max-width: 1024px) { "
"#back {padding-right: 14.5%}"
"#send {width: 14.5%}}"
"@media only screen and (max-width: 770px){ "
"#back {padding-right: 14.5%}"
"#send {width: 14.5%}}"
"@media only screen and (max-width: 440px) { "
"#back {padding-right: 17.5%}"
"#send {width: 17.5%}}"
"@media only screen and (max-width: 392px) { "
"#back {padding-right: 19%}"
"#send {width: 19%}}"
"@media only screen and (min-width: 321px) and (max-width: 350px) { "
"#back {padding-right: 21%}"
"#send {width: 21%}}"
"@media only screen and (min-width: 250px) and (max-width: 320px) { "
"#back {padding-right: 25%}"
"#send {width: 25%}}"
)
with interface:
logos = gr.Image(value=logo_path, interactive=False, show_label=False, elem_id="logo")
logos.style(height=100)
chatbot = gr.Chatbot(value=intro, label="Conversation")
chatbot.style(height=420)
message = gr.Textbox(placeholder="Send a message", show_label=False, elem_id="back")
message.style(container=True)
state = gr.State()
send = gr.Button("Send", elem_id="send")
#message.submit(conversation_history, [message, state], [chatbot, state], queue=False, show_progress=False)
#message.submit(lambda x: gr.update(value=""), [state], [message], queue=False, show_progress=False)
send.click(conversation_history, inputs=[message, state], outputs=[chatbot, state])
send.click(lambda x: gr.update(value=""), [state], [message], queue=False)
send.style(size="lg")
interface.launch(favicon_path="images/favicon.png")
|