import os import gradio as gr from together import Together # Function to interact with the model and process responses def chatbot_response(query): # Hugging Face API key setup (replace with your actual key) api_key = os.getenv("TOGETHER_API_KEY") if not api_key: return "Error: API key not found. Please configure your TOGETHER_API_KEY." client = Together(api_key=api_key) # Chat request to Hugging Face model response = client.chat.completions.create( model="NousResearch/Hermes-3-Llama-3.1-405B-Turbo", messages=[{"role": "user", "content": query}], ) # Extract and return the response return response.choices[0].message.content # Navigation and feature-specific responses def website_navigation(query): lower_query = query.lower() if "mentorship" in lower_query: return "You can explore our mentorship programs here: [Mentorship Program](#)" elif "alumni events" in lower_query or "meetups" in lower_query: return "Check out upcoming alumni events: [Alumni Events](#)" elif "career guidance" in lower_query: return "For career guidance sessions, visit: [Career Guidance](#)" elif "academic support" in lower_query: return "Need academic support? Find resources here: [Academic Support](#)" elif "placement assistance" in lower_query: return "Our placement assistance services are available here: [Placement Assistance](#)" elif "forums" in lower_query or "discussions" in lower_query: return "Join discussions on our forum: [Discussion Forums](#)" else: # Fallback to AI-generated responses return chatbot_response(query) # Gradio Interface with gr.Blocks() as demo: gr.Markdown("

Alumni-Student Interaction Platform Assistant

") gr.Markdown("Ask me about mentorship, alumni events, career guidance, academic support, placement assistance, or anything related to our platform.") chatbot = gr.Chatbot() query_input = gr.Textbox(placeholder="Type your question here (e.g., 'How can I find career guidance?')") def respond(query, chat_history): # Get response from website navigation or AI response = website_navigation(query) chat_history.append((query, response)) return chat_history, chat_history query_input.submit(respond, [query_input, chatbot], [chatbot, chatbot]) # Launch the app demo.launch()