Spaces:
Sleeping
Sleeping
Update app.py
Browse files7 unmodified lines89101112131415161718192021222324252627282930313233343536373839404142434445464713 unmodified lines616263646566676869707172737475767778798081828384858687881 unmodified line909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301317 unmodified lines# Function to get response from GROQ APIdef get_groq_response(message, category):# Define system message based on categorysystem_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.","Funny": "Respond with humorous remarks and witty commentary. Be entertaining but remain respectful.","Flirty": "Respond playfully and with charm. Keep it light-hearted, fun, and appropriate.","Scary": "Respond with spooky or thrilling remarks. Set a mysterious and eerie tone.","Business Mind": "Respond with a sharp, professional focus. Offer strategic advice and maintain a results-driven tone.","Extrovert": "Respond with high energy and enthusiasm. Be engaging, sociable, and vibrant.","Friendly Buddy": "Respond as a supportive and fun friend. Be informal, cheerful, and light-hearted.","Study Tips": "Provide effective study strategies, time management advice, and tips for staying organized and focused.","Exam Preparation": "Offer tips for preparing for exams, managing anxiety, and optimizing performance on test day.","Project Guidance": "Provide advice on how to tackle academic projects, group assignments, and presentations effectively.","Time Management": "Help the user manage their time effectively with practical scheduling and prioritization tips.","Motivation & Focus": "Provide encouraging advice to stay motivated and maintain focus on long-term goals.","Building Confidence": "Offer advice to help boost self-esteem, overcome self-doubt, and build confidence.","Friendship & Social Skills": "Provide tips for making friends, improving communication skills, and navigating social dynamics.","Networking & Career Building": "Offer advice on networking, building professional relationships, and finding internships or job opportunities.","Work-Life Balance": "Help the user balance academics, social life, and personal well-being.","Mental Health": "Provide empathetic advice to manage stress, anxiety, and other mental health challenges. Encourage seeking professional help when needed.","Physical Health": "Share tips for maintaining physical health, including fitness, sleep, and nutrition.","Budgeting Tips": "Provide practical advice for managing money, creating a budget, and saving effectively as a student.","Finding Part-Time Jobs": "Share tips for finding and balancing part-time work with academic responsibilities.","Scholarships & Financial Aid": "Provide advice on applying for scholarships, grants, and understanding financial aid options.","Resume Building": "Offer tips for creating an impressive resume tailored for internships or entry-level positions.","Interview Preparation": "Provide advice on how to prepare for interviews, including common questions and presentation tips.","Skill Development": "Suggest ways to build skills, gain certifications, and stand out in competitive fields.","Exploring New Hobbies": "Encourage trying new activities and provide ideas for hobbies that fit college life.","Clubs & Extracurriculars": "Offer advice on joining clubs, participating in activities, and enhancing the college experience.","Creative Projects": "Provide inspiration and resources for personal or group creative endeavors.",}system_message = system_messages.get(category, "Category not recognized. Respond appropriately to the user's input.")try:response = openai.ChatCompletion.create(13 unmodified lineshistory.append((f"You: {user_input}", f"Bot: {bot_response}"))return history, history# Categories grouped into main and subcategoriescategories = {"Academic Support": ["Study Tips", "Exam Preparation", "Project Guidance", "Time Management", "Building Confidence"],"Mental & Physical Wellness": ["Stress Management", "Motivation & Focus", "Mental Health", "Physical Health", "Work-Life Balance"],"Career & Financial": ["Networking & Career Building", "Finding Part-Time Jobs", "Scholarships & Financial Aid","Resume Building", "Interview Preparation", "Budgeting Tips", "Skill Development"],"Social & Personal Growth": ["Friendship & Social Skills", "Exploring New Hobbies", "Clubs & Extracurriculars", "Creative Projects"],"Fun & Miscellaneous": ["Funny", "Flirty", "Scary", "Business Mind", "Extrovert", "Friendly Buddy"]}# Gradio Interface with grouped categorieswith gr.Blocks() as chat_interface:with gr.Row():gr.Markdown("<h1 style='text-align:center;'>🌟 Vibrant Personal Assistant Chatbot 🌈</h1>")1 unmodified linegr.Markdown("<p style='text-align:center;'>Select a category and type your message to get tailored responses.</p>")with gr.Row():main_category = gr.Radio(label="Main Category",choices=list(categories.keys()),value="Academic Support")sub_category = gr.Dropdown(label="Subcategory",choices=categories["Academic Support"],value="Study Tips")def update_subcategories(selected_main_category):"""Update the subcategory dropdown based on the main category."""new_subcategories = categories.get(selected_main_category, [])return gr.update(choices=new_subcategories, value=new_subcategories[0] if new_subcategories else None)# Handle main category change to update subcategoriesmain_category.change(update_subcategories, inputs=main_category, outputs=sub_category)with gr.Row():user_input = gr.Textbox(label="Your Message", placeholder="Type something...", lines=2)send_button = gr.Button("Send")with gr.Row():chatbot_output = gr.Chatbot(label="Chat History")def handle_chat(user_input, sub_category, history):if not user_input.strip():return history, historyupdated_history, _ = chatbot(user_input, sub_category, history)return updated_history, updated_historysend_button.click(handle_chat,inputs=[user_input, sub_category, chatbot_output],outputs=[chatbot_output, chatbot_output])chat_interface.launch()7 unmodified lines89101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585913 unmodified lines7374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291 unmodified line1311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661677 unmodified lines# Function to get response from GROQ APIdef get_groq_response(message, category):system_message = ""if category == "Study Tips":system_message = "Provide effective study strategies, time management advice, and tips for staying organized and focused."elif category == "Exam Preparation":system_message = "Offer tips for preparing for exams, managing anxiety, and optimizing performance on test day."elif category == "Project Guidance":system_message = "Provide advice on how to tackle academic projects, group assignments, and presentations effectively."elif category == "Time Management":system_message = "Help the user manage their time effectively with practical scheduling and prioritization tips."elif category == "Motivation & Focus":system_message = "Provide encouraging advice to stay motivated and maintain focus on long-term goals."elif category == "Building Confidence":system_message = "Offer advice to help boost self-esteem, overcome self-doubt, and build confidence."elif category == "Friendship & Social Skills":system_message = "Provide tips for making friends, improving communication skills, and navigating social dynamics."elif category == "Networking & Career Building":system_message = "Offer advice on networking, building professional relationships, and finding internships or job opportunities."elif category == "Work-Life Balance":system_message = "Help the user balance academics, social life, and personal well-being."elif category == "Mental Health":system_message = "Provide empathetic advice to manage stress, anxiety, and other mental health challenges. Encourage seeking professional help when needed."elif category == "Physical Health":system_message = "Share tips for maintaining physical health, including fitness, sleep, and nutrition."elif category == "Stress Management":system_message = "Offer calming techniques and advice to handle stress effectively."elif category == "Budgeting Tips":system_message = "Provide practical advice for managing money, creating a budget, and saving effectively as a student."elif category == "Finding Part-Time Jobs":system_message = "Share tips for finding and balancing part-time work with academic responsibilities."elif category == "Scholarships & Financial Aid":system_message = "Provide advice on applying for scholarships, grants, and understanding financial aid options."elif category == "Resume Building":system_message = "Offer tips for creating an impressive resume tailored for internships or entry-level positions."elif category == "Interview Preparation":system_message = "Provide advice on how to prepare for interviews, including common questions and presentation tips."elif category == "Skill Development":system_message = "Suggest ways to build skills, gain certifications, and stand out in competitive fields."elif category == "Exploring New Hobbies":system_message = "Encourage trying new activities and provide ideas for hobbies that fit college life."elif category == "Clubs & Extracurriculars":system_message = "Offer advice on joining clubs, participating in activities, and enhancing the college experience."elif category == "Creative Projects":system_message = "Provide inspiration and resources for personal or group creative endeavors."else:system_message = "Category not recognized. Respond appropriately to the user's input."try:response = openai.ChatCompletion.create(13 unmodified lineshistory.append((f"You: {user_input}", f"Bot: {bot_response}"))return history, history# Gradio Interface with enhanced stylingchat_interface = gr.Blocks(css="""body {font-family: 'Poppins', sans-serif;background: linear-gradient(120deg, #ff9a9e, #fad0c4, #a1c4fd);animation: gradientBG 10s ease infinite;margin: 0;padding: 0;color: #333;}@keyframes gradientBG {0% { background-position: 0% 50%; }50% { background-position: 100% 50%; }100% { background-position: 0% 50%; }}button {background: linear-gradient(90deg, #6a11cb, #2575fc);color: white;padding: 0.8rem 1.5rem;font-size: 1rem;font-weight: bold;border-radius: 20px;border: none;cursor: pointer;transition: transform 0.2s ease, background 0.2s ease;}button:hover {background: linear-gradient(90deg, #2575fc, #6a11cb);transform: scale(1.1);}header {text-align: center;margin-bottom: 20px;padding: 10px;border-radius: 15px;background: linear-gradient(90deg, #ff758c, #ff7eb3);color: white;box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);}.chat-container {border: 2px solid #ff7eb3;background: rgba(255, 255, 255, 0.8);border-radius: 15px;padding: 15px;box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);max-height: 300px;overflow-y: auto;}""")with chat_interface:with gr.Row():gr.Markdown("<h1 style='text-align:center;'>🌟 Vibrant Personal Assistant Chatbot 🌈</h1>")1 unmodified linegr.Markdown("<p style='text-align:center;'>Select a category and type your message to get tailored responses.</p>")with gr.Row():user_input = gr.Textbox(label="Your Message", placeholder="Type something...", lines=2)category_dropdown = gr.Dropdown(choices=["Study Tips", "Exam Preparation", "Project Guidance", "Time Management", "Motivation & Focus","Building Confidence", "Friendship & Social Skills", "Networking & Career Building", "Work-Life Balance","Mental Health", "Physical Health", "Stress Management", "Budgeting Tips", "Finding Part-Time Jobs","Scholarships & Financial Aid", "Resume Building", "Interview Preparation", "Skill Development","Exploring New Hobbies", "Clubs & Extracurriculars", "Creative Projects"],label="Choose Chat Category")with gr.Row():send_button = gr.Button("Send")with gr.Row():with gr.Column() as chat_container:chatbot_output = gr.Chatbot(label="Chat History")# Add functionality to handle interactionsdef handle_chat(user_input, category, history):if not user_input.strip():return history, historyupdated_history, _ = chatbot(user_input, category, history)return updated_history, updated_historysend_button.click(handle_chat,inputs=[user_input, category_dropdown, chatbot_output],outputs=[chatbot_output, chatbot_output])chat_interface.launch()
app.py+114-78