Spaces:
Running
Running
| import gradio as gr | |
| import random | |
| import numpy as np | |
| from huggingface_hub import InferenceClient | |
| from sentence_transformers import SentenceTransformer | |
| custom_theme = gr.themes.Soft( | |
| primary_hue="pink", | |
| secondary_hue="fuchsia", | |
| neutral_hue="rose", | |
| spacing_size="lg", | |
| radius_size="lg", | |
| text_size="lg", | |
| font=[gr.themes.GoogleFont("Montserrat"), "montserrat"], | |
| font_mono=[gr.themes.GoogleFont("IBM Plex Mono"), "monospace"] | |
| ) | |
| # chatbot.launch(ssr_mode=False) | |
| embedding_model = SentenceTransformer("all-MiniLM-L6-v2") | |
| client = InferenceClient("Qwen/Qwen2.5-7B-Instruct") | |
| with open("knowledge.txt", "r", encoding="utf-8") as f: | |
| positive_messages = [line.strip() for line in f if line.strip()] | |
| def lucky_dumpling(): | |
| return random.choice(positive_messages) | |
| def college_chatbot(message, history): | |
| messages = [{"role": "system", "content":"Your name is CASP. You are running a college interactive quiz. This is the quiz questions: What grade are you in? Share any awards/standardized testing scores. What are your major interests or field of study? What is your desired competitiveness level? Do you have a preferred location or region? What is your approximate budget for college?, Give a very detailed summarization of their answers, send the results and save them in the college information tab, and tell the user that their results have been saved and to then move into the College Information Tab. Be conversational and only ask one question at a time. Using these results, act as a highly empathetic and expert personal college guidance advisor and academic counselor. Your sole mission is to provide deeply personalized, actionable, and structured college and summer program recommendations based directly on a user's needs. When reviewing the user's data, you will analyze their academic profile, including their current grades, GPA, and test scores, alongside their specific personal preferences such as major or area of interest, desired competitiveness level ranging from highly competitive to safety options, location preferences including in-state versus out-of-state, and campus vibe or program type. Once you have absorbed their results, you will synthesize this information to craft a comprehensive, encouraging, and highly detailed recommendation report. You will begin your response with a warm, welcoming introduction that establishes a supportive, mentorship-based tone. Following this introduction, you will provide a categorized breakdown of colleges that fit their exact profile, explicitly dividing your suggestions into tiers such as reach, target, and likely or safety schools, or alternatively categorizing summer programs by skill level and intensity. For each recommendation, you must explain exactly why the institution or program aligns with their preferences, detailing key attributes such as average accepted GPA, program strengths in their intended major, campus culture, location, and the level of selectivity. You will then provide concrete, actionable next steps tailored to their current grade level, such as suggesting standardized testing timelines, specific extracurricular activities, or campus visits they should prioritize. You must base your recommendations entirely on realistic educational data and avoid making up false programs, universities, or statistics, always ensuring your advice is structured logically and reads like an expert counselor who is fully invested in the student's success. Your tone should be encouraging, professional, and accessible, ensuring the student leaves the conversation feeling informed, motivated, and make sure to give a clear roadmap on what to do next to optimize their chances for success in college admissions for their academic future."}] | |
| if history: | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": message}) | |
| response = client.chat_completion( | |
| messages, | |
| max_tokens = 2100 | |
| ) | |
| return response.choices[0].message.content.strip() | |
| def summer_chatbot(message, history): | |
| messages = [{"role": "system", "content":"You are an expert summer program guidance advisor. Your primary mission is to give them clear, highly personalized recommendations for summer programs that perfectly align with their specific needs. It is crucial that you strictly focus ONLY on summer programs and exclude any full-time colleges or universities, as those are handled in a separate application tab. For each user, you will synthesize their answers regarding their preferred level of program competitiveness ranging from highly selective to low-competition, their geographic preferences including in-state, out-of-state, or virtual options, their current grade level, and their intended areas of study or majors. You must also account for any other necessary details they provide to narrow down the decision, such as program duration, budget, and prerequisite requirements. When delivering your recommendations, you will write in the enthusiastic, encouraging, and knowledgeable tone of a personal educational counselor. You will provide comprehensive details for each recommended summer program, including program names, focus areas, key dates, admission difficulty, cost, and a clear explanation of why the experience is a perfect fit for the student's unique profile and career aspirations. You will craft your response in bullet points, so that it's easy to remember all that information. Important to note if the user took the quiz in the college tab, because it they have not then you may ask 5 questions to help you with giving them their output. Conclude with actionable next steps to help them prepare their applications." }] | |
| if history: | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": message}) | |
| response = client.chat_completion ( | |
| messages, | |
| max_tokens = 2100 | |
| ) | |
| return response.choices[0].message.content.strip() | |
| def stress_chatbot(message, history): | |
| messages = [{"role": "system", "content":"Your name is CASP and you are a highly empathetic and expert personal therapist and counselor. Your mission is to give stress tips to the student to manage stress during the college admission/summer program application process, as well as school in general." }] | |
| if history: | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": message}) | |
| response = client.chat_completion ( | |
| messages, | |
| max_tokens = 2100 | |
| ) | |
| return response.choices[0].message.content.strip() | |
| college = gr.ChatInterface( | |
| college_chatbot, | |
| title="π College Guidance π", | |
| description="Personalized college recommendations based on your interests.", | |
| textbox=gr.Textbox(placeholder="Ask Me Anything..."), | |
| examples=[ | |
| "Let's start the quiz!", | |
| "I want to study Computer Science at a target school.", | |
| "What affordable colleges have strong pre med programs?" | |
| ] | |
| ) | |
| stress = gr.ChatInterface( | |
| stress_chatbot, | |
| title="π Stress Support π", | |
| description="Advice and strategies for managing pressure.", | |
| textbox=gr.Textbox(placeholder="Ask Me Anything..."), | |
| examples=[ | |
| "I'm overwhelmed by college applications.", | |
| "How do I deal with rejection from my dream school?", | |
| "Tips for managing anxiety during application season?" | |
| ] | |
| ) | |
| summer = gr.ChatInterface( | |
| summer_chatbot, | |
| title="π Summer Programs π", | |
| description="Find opportunities that match your goals.", | |
| textbox=gr.Textbox(placeholder="Ask Me Anything..."), | |
| examples=[ | |
| "Let's find summer programs for me!", | |
| "What are free STEM summer programs for high schoolers?", | |
| "I want a competitivive research program for my grade." | |
| ] | |
| ) | |
| with gr.Blocks(theme=custom_theme) as demo: | |
| gr.Image(value="Casp2.png", show_label=False, elem_id="top-image") | |
| gr.Markdown(""" | |
| <div style="text-align:center"> | |
| <h1 class="glow">Hi, I'm CASP! π</h1> | |
| <p style="font-size:18px; max-width:600px; margin:0 auto; color:#ff69b4;"> | |
| I'm your AI college, summer program, and stress advisor. | |
| </p> | |
| </div> | |
| <style> | |
| .glow { | |
| color: #ff4da6; | |
| text-shadow: | |
| 0 0 5px #ff4da6, | |
| 0 0 10px #ff4da6, | |
| 0 0 20px #ff69b4, | |
| 0 0 40px #ff69b4; | |
| font-size: 52px; | |
| margin-bottom: 10px; | |
| } | |
| "<h1 style='text-align:center'>:mortar_board: College Guidance :mortar_board:</h1> | |
| <p style='text-align:center'>Personalized college recommendations based on your interests.</p> | |
| </style> | |
| """) | |
| gr.TabbedInterface([ college, summer, stress], [ "College Information", "Summer Programs", "Stress Tips" ]) | |
| gr.Markdown(""" | |
| <h2 style="text-align:center; color:#ff69b4;"> | |
| π₯ Lucky Dumplings π₯ | |
| </h2> | |
| <p style="text-align:center;"> | |
| Click a dumpling for a little encouragement! | |
| </p> | |
| """) | |
| with gr.Row(): | |
| dumpling2 = gr.Image("dumpling2.png", interactive=True, show_label=False) | |
| dumpling1 = gr.Image("dumpling1.png", interactive=True, show_label=False) | |
| dumpling3 = gr.Image("dumpling3.png", interactive=True, show_label=False) | |
| message_box = gr.Textbox(label="CASP's Message π", interactive=False) | |
| dumpling2.select(lucky_dumpling, outputs=message_box) | |
| dumpling1.select(lucky_dumpling, outputs=message_box) | |
| dumpling3.select(lucky_dumpling, outputs=message_box) | |
| demo.launch(debug="True") |