import gradio as gr import openai import os # Set OpenAI API Key openai.api_key = os.getenv("TRY_NEW_THINGS") openai.api_base = "https://api.groq.com/openai/v1" # Function to get response from OpenAI API def get_groq_response(message, category): # Define system message based on category system_messages = { "Stress Management": "Provide soothing advice and tips to help the user manage stress. Be calm, empathetic, and reassuring.", "Career Advice": "Offer professional and constructive career advice. Be encouraging, insightful, and action-oriented.", "General": "Engage in general conversation. Be friendly, approachable, and easygoing.", # Add more categories as needed... } system_message = system_messages.get(category, "Respond appropriately to the user's input.") try: response = openai.ChatCompletion.create( model="llama-3.1-70b-versatile", messages=[ {"role": "system", "content": system_message}, {"role": "user", "content": message} ] ) return response.choices[0].message["content"] except Exception as e: return f"Error: {str(e)}" # Chatbot function def chatbot(user_input, category, history=[]): bot_response = get_groq_response(user_input, category) history.append((user_input, bot_response)) return history, history # Categories categories = { "Academic Support": ["Study Tips", "Exam Preparation", "Project Guidance", "Time Management"], "Mental & Physical Wellness": ["Stress Management", "Motivation & Focus", "Mental Health", "Physical Health"], "Career & Financial": ["Networking & Career Building", "Resume Building", "Interview Preparation"], } # Gradio Interface with gr.Blocks() as chat_interface: with gr.Row(): gr.Markdown("