soleilholmes commited on
Commit
375c9bd
·
verified ·
1 Parent(s): efaa320

added banner

Browse files
Files changed (1) hide show
  1. app.py +28 -25
app.py CHANGED
@@ -1,14 +1,20 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient #imports huggingface models
3
 
4
- # NEW LIBRARIES
5
 
6
  from sentence_transformers import SentenceTransformer
7
  import torch
8
- import numpy as np
9
 
 
 
 
 
 
 
 
 
10
 
11
- ## START NEW CODE
12
 
13
  # Load and process the knowledge base text file
14
  with open("knowledge.txt", "r", encoding="utf-8") as f:
@@ -46,18 +52,12 @@ def get_relevant_context(query, top_k=3):
46
  context = "\n\n".join([chunks[i] for i in top_k_indices])
47
  return context
48
 
49
- ## END OF NEW CODE
50
-
51
  client = InferenceClient("google/gemma-2-2b-it")
52
 
53
  def respond(message, history):
54
  messages = [{"role": "system", "content": "You are PrisMate, an encouraging AI mentor and girlboss energy assistant for high school students and aspiring women/minorities in tech. Your mission is to share hidden tech history, resources, and communities that combat cultural erasure while building inclusive pathways into technology careers. You know the contributions of underrepresented pioneers, specific organizations and scholarships, mentorship programs, and practical career guidance. Be genuinely personable and helpful—keep responses short, concise, and clear while being warm, encouraging, and culturally aware with that empowering feminine energy. Only discuss topics relevant to tech careers, education, and supporting underrepresented groups in technology. If asked about unrelated topics (like food, entertainment, etc.), politely redirect by saying something like I'm here to support you on your tech journey! Let's talk about how I can help you succeed in technology. Provide actionable advice with concrete next steps, highlight overlooked historical figures, connect students to relevant communities, and help them see their backgrounds as strengths. Explain concepts at high school level and always end with something they can do right away."}]
55
 
56
- # NEW CODE
57
- # Retrieve context relevant to the current user message
58
- context = get_relevant_context(message, top_k=3)
59
-
60
- # add all previous messages to the messages list
61
  if history:
62
  for user_msg, assistant_msg in history:
63
  messages.append({"role": "user", "content": user_msg})
@@ -74,21 +74,24 @@ def respond(message, history):
74
  # iterate through each message in the method
75
  for message in client.chat_completion(
76
  messages,
77
- max_tokens=300,
78
  temperature=.1,
79
  stream=True):
 
80
  # add the tokens to the output content
81
- token = message.choices[0].delta.content # capture the most recent toke
82
- response += token # Add it to the response
83
- yield response # yield the response:
84
-
85
- # Define the chatbot interface outside the respond function
86
- chatbot_interface = gr.ChatInterface(
87
- respond,
88
- examples=["Teach me about minorities in tech", "Help me find statistics about Women in tech", "What are some communities/groups I can join for tech inclusiveness!"],
89
- title="PrisMate",
90
- description="This is a minority inclusivity bot"
91
- )
92
-
93
- # Launch the chatbot interface
94
- chatbot_interface.launch()
 
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient #imports huggingface models
3
 
 
4
 
5
  from sentence_transformers import SentenceTransformer
6
  import torch
7
+ import numpy as np
8
 
9
+ with gr.Blocks() as chatbot:
10
+ gr.Image(
11
+ value="orange-banner.png",
12
+ show_label=False,
13
+ show_share_button = False,
14
+ show_download_button = False)
15
+
16
+ #Set Hugging Face Token so it works in google colab - PASTE YOUR CODE HERE
17
 
 
18
 
19
  # Load and process the knowledge base text file
20
  with open("knowledge.txt", "r", encoding="utf-8") as f:
 
52
  context = "\n\n".join([chunks[i] for i in top_k_indices])
53
  return context
54
 
 
 
55
  client = InferenceClient("google/gemma-2-2b-it")
56
 
57
  def respond(message, history):
58
  messages = [{"role": "system", "content": "You are PrisMate, an encouraging AI mentor and girlboss energy assistant for high school students and aspiring women/minorities in tech. Your mission is to share hidden tech history, resources, and communities that combat cultural erasure while building inclusive pathways into technology careers. You know the contributions of underrepresented pioneers, specific organizations and scholarships, mentorship programs, and practical career guidance. Be genuinely personable and helpful—keep responses short, concise, and clear while being warm, encouraging, and culturally aware with that empowering feminine energy. Only discuss topics relevant to tech careers, education, and supporting underrepresented groups in technology. If asked about unrelated topics (like food, entertainment, etc.), politely redirect by saying something like I'm here to support you on your tech journey! Let's talk about how I can help you succeed in technology. Provide actionable advice with concrete next steps, highlight overlooked historical figures, connect students to relevant communities, and help them see their backgrounds as strengths. Explain concepts at high school level and always end with something they can do right away."}]
59
 
60
+ # add all previous messages to the messages list
 
 
 
 
61
  if history:
62
  for user_msg, assistant_msg in history:
63
  messages.append({"role": "user", "content": user_msg})
 
74
  # iterate through each message in the method
75
  for message in client.chat_completion(
76
  messages,
77
+ max_tokens=500,
78
  temperature=.1,
79
  stream=True):
80
+
81
  # add the tokens to the output content
82
+ token = message.choices[0].delta.content # capture the most recent toke
83
+ response += token # Add it to the response
84
+ yield response # yield the response:
85
+
86
+ with gr.Blocks() as chatbot:
87
+ gr.Image(
88
+ value="banner.jpg",
89
+ show_label=False,
90
+ show_share_button=False,
91
+ show_download_button=False
92
+ )
93
+
94
+
95
+ gr.ChatInterface(respond, type="messages") #make sure you only have this line ONCE
96
+
97
+ chatbot.launch()