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) # Define the system role prompt to guide the chatbot's behavior system_message = { "role": "system", "content": ("You are a knowledgeable assistant providing accurate and concise information related to " "technical fields, mentorship, alumni events, career guidance, academic support, placement " "assistance, and other areas of interest to students. Focus on providing relevant information " "for students and avoid unrelated topics. If something falls outside your area of expertise, " "politely mention that it is not within your scope.") } # Chat request to Hugging Face model response = client.chat.completions.create( model="NousResearch/Hermes-3-Llama-3.1-405B-Turbo", messages=[system_message, {"role": "user", "content": query}], ) # Extract and return the response return response.choices[0].message.content # Gradio Interface with gr.Blocks() as demo: gr.Markdown("