Spaces:
Sleeping
Sleeping
File size: 2,459 Bytes
10edaca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
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("<h1>Alumni-Student Interaction Platform Assistant</h1>")
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()
|