diff --git a/app.py b/app.py index 974d530..3bc485a 100644 --- a/app.py +++ b/app.py @@ -13,17 +13,34 @@ SYSTEM_PROMPT = { "content": "You are CheerMate, the optimistic friend! Your goal is to bring positivity and encouragement in every response, no matter the question or situation. Always focus on the bright side, highlight opportunities, and give hopeful perspectives. If there's a challenge, emphasize resilience and personal growth. Keep your tone friendly, cheerful, and upliftingโ€”you're here to make people smile and feel motivated!" } -with gr.Blocks(css="footer {visibility: hidden}") as demo: - chatbot = gr.Chatbot(type="messages") - msg = gr.Textbox() - clear = gr.Button("Clear") +# Background CSS to include a background image +BACKGROUND_CSS = """ +body { + background-image: url('https://example.com/path/to/your/background-image.jpg'); + background-size: cover; +} +footer { + visibility: hidden; +} +""" - def user(user_message, history: list): - """Appends the user message to the conversation history.""" +# Custom Gradio app with additional features +with gr.Blocks(css=BACKGROUND_CSS) as demo: + # User input components + user_name = gr.Textbox(label="Enter your name", placeholder="Your name here...", value="Guest") + emotion_picker = gr.Dropdown(choices=["๐Ÿ™‚", "๐Ÿ˜Š", "๐Ÿ˜ก", "๐Ÿ˜ข", "๐Ÿ˜Ž"], label="Select your mood", value="๐Ÿ™‚") + chatbot = gr.Chatbot(type="messages") + msg = gr.Textbox(placeholder="Type your message here...") + clear = gr.Button("Clear") + save_chat = gr.Button("Save Chat History") + + def user(user_message, user_name, mood, history: list): + """Appends the user message to the conversation history, prefixed with the user name and mood.""" # If the system prompt is not in the history, add it if not history: history = [SYSTEM_PROMPT] - return "", history + [{"role": "user", "content": user_message}] + formatted_message = f"{user_name} ({mood}): {user_message}" + return "", history + [{"role": "user", "content": formatted_message}] def bot(history: list): """Sends the conversation history to the vLLM API and streams the assistant's response.""" @@ -52,11 +69,17 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo: history[-1]['content'] += f"\n[Error]: {str(e)}" yield history + def save_history(history): + """Saves the conversation history to a text file.""" + chat_history = "\n".join([f"{item['role'].capitalize()}: {item['content']}" for item in history]) + return chat_history + # Set up the Gradio interface components - msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then( + msg.submit(user, [msg, user_name, emotion_picker, chatbot], [msg, chatbot], queue=False).then( bot, chatbot, chatbot ) clear.click(lambda: None, None, chatbot, queue=False) + save_chat.click(lambda history: gr.File.update(value=save_history(history)), chatbot) if __name__ == "__main__": demo.launch()