DhruvDecoder commited on
Commit
10edaca
·
verified ·
1 Parent(s): 9664fd1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from together import Together
4
+
5
+ # Function to interact with the model and process responses
6
+ def chatbot_response(query):
7
+ # Hugging Face API key setup (replace with your actual key)
8
+ api_key = os.getenv("TOGETHER_API_KEY")
9
+ if not api_key:
10
+ return "Error: API key not found. Please configure your TOGETHER_API_KEY."
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
+
57
+ query_input.submit(respond, [query_input, chatbot], [chatbot, chatbot])
58
+
59
+ # Launch the app
60
+ demo.launch()