File size: 2,189 Bytes
6517515
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3cfcbf6
6517515
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
import streamlit as st
from huggingface_hub import InferenceClient
from dotenv import load_dotenv
import os

# Load .env file
load_dotenv()

# Get API key from environment variable
api_key = os.getenv("HUGGINGFACEHUB_API_TOKEN")

st.set_page_config(page_title="Intellicounsel AI Chat", page_icon="πŸ€–")

# Add system prompt once at the start
system_prompt = {
    "role": "system",
    "content": (
        "You are Intellicounsel, an intelligent and friendly AI advisor that helps students "
        "with college applications, SOP reviews, resume tips, and academic advice. "
        "Respond clearly and helpfully, always tailored to the student's needs."
    )
}

# Initialize chat history
if "messages" not in st.session_state:
    st.session_state.messages = []

# Title
st.title("🧠 Intellicounsel β€” AI College Advisor")

# User input
user_input = st.chat_input("Ask something like SOP tips or university suggestions...")

# Show past messages
for msg in st.session_state.messages:
    with st.chat_message(msg["role"]):
        st.markdown(msg["content"])

# If new input
if user_input:
    st.session_state.messages.append({"role": "user", "content": user_input})

    with st.chat_message("user"):
        st.markdown(user_input)

    with st.chat_message("assistant"):
        with st.spinner("Thinking..."):
            try:
                client = InferenceClient(
                    model="nvidia/Llama-3_1-Nemotron-Ultra-253B-v1",
                    provider="nebius",
                    api_key=api_key,
                )

                # Add system prompt only once at the start of the context
                full_context = [system_prompt] + st.session_state.messages

                completion = client.chat.completions.create(
                    model="nvidia/Llama-3_1-Nemotron-Ultra-253B-v1",
                    messages=full_context,
                    max_tokens=2048,
                )

                response = completion.choices[0].message.content

            except Exception as e:
                response = f"❌ Error: {e}"

        st.markdown(response)
        st.session_state.messages.append({"role": "assistant", "content": response})