import gradio as gr import openai import os # Set OpenAI API Key openai.api_key = os.getenv("GROQ_API_KEY") openai.api_base = "https://api.groq.com/openai/v1" # Dictionary to store categorized chats saved_chats = { "Stress Management": [], "Career Advice": [], "General": [], "Suggestions": [] } # Function to get response from GROQ API def get_groq_response(message): try: response = openai.ChatCompletion.create( model="llama-3.1-70b-versatile", messages=[ {"role": "user", "content": message}, {"role": "system", "content": "You will talk like a Motivational Speaker to help people come out of stress."} ] ) return response.choices[0].message["content"] except Exception as e: return f"Error: {str(e)}" # Function to classify messages based on the topic def classify_message(user_message, bot_response): if "stress" in user_message.lower(): saved_chats["Stress Management"].append((user_message, bot_response)) return "Stress Management" elif "career" in user_message.lower(): saved_chats["Career Advice"].append((user_message, bot_response)) return "Career Advice" elif "suggestions" in user_message.lower(): saved_chats["Suggestions"].append((user_message, bot_response)) return "Suggestions" else: saved_chats["General"].append((user_message, bot_response)) return "General" # Chatbot function def chatbot(user_input, history=[]): bot_response = get_groq_response(user_input) topic = classify_message(user_input, bot_response) history.append((f"({topic}) You: {user_input}", f"Motivator Bot: {bot_response}")) return history, saved_chats # Custom HTML, CSS, and JavaScript custom_html = """
Your personal motivational speaker!