yogarajas commited on
Commit
95f5056
·
verified ·
1 Parent(s): 59d2bf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -54
app.py CHANGED
@@ -1,69 +1,81 @@
1
  import gradio as gr
 
 
2
  from huggingface_hub import InferenceClient
 
3
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- def respond(
6
- message,
7
- history: list[dict[str, str]],
8
- system_message,
9
- max_tokens,
10
- temperature,
11
- top_p,
12
- hf_token: gr.OAuthToken,
13
- ):
14
- """
15
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
16
- """
17
- client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
18
-
19
- messages = [{"role": "system", "content": system_message}]
20
 
21
- messages.extend(history)
 
22
 
23
- messages.append({"role": "user", "content": message})
 
24
 
25
- response = ""
26
 
27
- for message in client.chat_completion(
 
 
 
 
 
 
28
  messages,
29
- max_tokens=max_tokens,
30
- stream=True,
31
- temperature=temperature,
32
- top_p=top_p,
33
- ):
34
- choices = message.choices
35
- token = ""
36
- if len(choices) and choices[0].delta.content:
37
- token = choices[0].delta.content
38
 
39
- response += token
40
- yield response
41
 
42
-
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- chatbot = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
60
  )
61
 
62
- with gr.Blocks() as demo:
63
- with gr.Sidebar():
64
- gr.LoginButton()
65
- chatbot.render()
66
 
67
 
68
- if __name__ == "__main__":
69
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import random
3
+ import numpy as np
4
  from huggingface_hub import InferenceClient
5
+ from sentence_transformers import SentenceTransformer
6
 
7
+ custom_theme = gr.themes.Soft(
8
+ primary_hue="blue",
9
+ secondary_hue="orange",
10
+ neutral_hue="rose",
11
+ spacing_size="lg",
12
+ radius_size="lg",
13
+ text_size="lg",
14
+ font=[gr.themes.GoogleFont("Montserrat"), "montserrat"],
15
+ font_mono=[gr.themes.GoogleFont("IBM Plex Mono"), "monospace"]
16
+
17
+ )
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
21
+ client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
22
 
23
+ with open("knowledge.txt", "r", encoding="utf-8") as f:
24
+ positive_messages = [line.strip() for line in f if line.strip()]
25
 
 
26
 
27
+ def college_chatbot(message, history):
28
+ 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."}]
29
+
30
+ if history:
31
+ messages.extend(history)
32
+ messages.append({"role": "user", "content": message})
33
+ response = client.chat_completion(
34
  messages,
35
+ max_tokens = 2100
36
+ )
37
+ return response.choices[0].message.content.strip()
 
 
 
 
 
 
38
 
 
 
39
 
40
+ college = gr.ChatInterface(
41
+ college_chatbot,
42
+ title="🎓 College Guidance 🎓",
43
+ description="Personalized college recommendations based on your interests.",
44
+ textbox=gr.Textbox(placeholder="Ask Me Anything..."),
45
+ examples=[
46
+ "Let's start the quiz!",
47
+ "I want to study Computer Science at a target school.",
48
+ "What affordable colleges have strong pre med programs?"
49
+ ]
 
 
 
 
 
 
 
 
50
  )
51
 
 
 
 
 
52
 
53
 
54
+ with gr.Blocks(theme=custom_theme) as demo:
55
+ gr.Image(value="Casp2.png", show_label=False, elem_id="top-image")
56
+ gr.Markdown("""
57
+ <div style="text-align:center">
58
+ <h1 class="glow">Hi, I'm TAC Bot! </h1>
59
+ <p style="font-size:18px; max-width:600px; margin:0 auto; color:#ff69b4;">
60
+ I'm going to help you with any questions you have for us:
61
+ </p>
62
+ </div>
63
+ <style>
64
+ .glow {
65
+ color: #ff4da6;
66
+ text-shadow:
67
+ 0 0 5px #ff4da6,
68
+ 0 0 10px #ff4da6,
69
+ 0 0 20px #ff69b4,
70
+ 0 0 40px #ff69b4;
71
+ font-size: 52px;
72
+ margin-bottom: 10px;
73
+ }
74
+ "<h1 style='text-align:center'>:mortar_board: College Guidance :mortar_board:</h1>
75
+ <p style='text-align:center'>Personalized college recommendations based on your interests.</p>
76
+ </style>
77
+ """)
78
+
79
+ gr.TabbedInterface([college], [ "TAC Information" ])
80
+
81
+ demo.launch(debug="True")