DhruvDecoder commited on
Commit
831d847
·
verified ·
1 Parent(s): d2046f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -24
app.py CHANGED
@@ -11,46 +11,36 @@ def chatbot_response(query):
11
 
12
  client = Together(api_key=api_key)
13
 
 
 
 
 
 
 
 
 
 
 
14
  # Chat request to Hugging Face model
15
  response = client.chat.completions.create(
16
  model="NousResearch/Hermes-3-Llama-3.1-405B-Turbo",
17
- messages=[{"role": "user", "content": query}],
18
  )
19
 
20
  # Extract and return the response
21
  return response.choices[0].message.content
22
 
23
- # Navigation and feature-specific responses
24
- def website_navigation(query):
25
- lower_query = query.lower()
26
-
27
- if "mentorship" in lower_query:
28
- return "You can explore our mentorship programs here: [Mentorship Program](#)"
29
- elif "alumni events" in lower_query or "meetups" in lower_query:
30
- return "Check out upcoming alumni events: [Alumni Events](#)"
31
- elif "career guidance" in lower_query:
32
- return "For career guidance sessions, visit: [Career Guidance](#)"
33
- elif "academic support" in lower_query:
34
- return "Need academic support? Find resources here: [Academic Support](#)"
35
- elif "placement assistance" in lower_query:
36
- return "Our placement assistance services are available here: [Placement Assistance](#)"
37
- elif "forums" in lower_query or "discussions" in lower_query:
38
- return "Join discussions on our forum: [Discussion Forums](#)"
39
- else:
40
- # Fallback to AI-generated responses
41
- return chatbot_response(query)
42
-
43
  # Gradio Interface
44
  with gr.Blocks() as demo:
45
  gr.Markdown("<h1>Alumni-Student Interaction Platform Assistant</h1>")
46
- gr.Markdown("Ask me about mentorship, alumni events, career guidance, academic support, placement assistance, or anything related to our platform.")
47
 
48
  chatbot = gr.Chatbot()
49
  query_input = gr.Textbox(placeholder="Type your question here (e.g., 'How can I find career guidance?')")
50
 
51
  def respond(query, chat_history):
52
- # Get response from website navigation or AI
53
- response = website_navigation(query)
54
  chat_history.append((query, response))
55
  return chat_history, chat_history
56
 
 
11
 
12
  client = Together(api_key=api_key)
13
 
14
+ # Define the system role prompt to guide the chatbot's behavior
15
+ system_message = {
16
+ "role": "system",
17
+ "content": ("You are a knowledgeable assistant providing accurate and concise information related to "
18
+ "technical fields, mentorship, alumni events, career guidance, academic support, placement "
19
+ "assistance, and other areas of interest to students. Focus on providing relevant information "
20
+ "for students and avoid unrelated topics. If something falls outside your area of expertise, "
21
+ "politely mention that it is not within your scope.")
22
+ }
23
+
24
  # Chat request to Hugging Face model
25
  response = client.chat.completions.create(
26
  model="NousResearch/Hermes-3-Llama-3.1-405B-Turbo",
27
+ messages=[system_message, {"role": "user", "content": query}],
28
  )
29
 
30
  # Extract and return the response
31
  return response.choices[0].message.content
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  # Gradio Interface
34
  with gr.Blocks() as demo:
35
  gr.Markdown("<h1>Alumni-Student Interaction Platform Assistant</h1>")
36
+ gr.Markdown("Ask me if you need any information or help.I am there to solve your queries!")
37
 
38
  chatbot = gr.Chatbot()
39
  query_input = gr.Textbox(placeholder="Type your question here (e.g., 'How can I find career guidance?')")
40
 
41
  def respond(query, chat_history):
42
+ # Get response from the chatbot
43
+ response = chatbot_response(query)
44
  chat_history.append((query, response))
45
  return chat_history, chat_history
46