67Ayush87 commited on
Commit
e1588f1
·
verified ·
1 Parent(s): acae1ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -4,28 +4,25 @@ from langchain_community.chat_models import ChatHuggingFace
4
  from langchain_community.llms import HuggingFaceEndpoint
5
  from langchain_core.messages import HumanMessage, SystemMessage, AIMessage
6
 
 
 
 
 
 
7
 
8
- hf_token = os.getenv("Data_science")
9
  os.environ["HUGGINGFACEHUB_API_KEY"] = hf_token
10
  os.environ["HF_TOKEN"] = hf_token
11
 
12
-
13
  model = HuggingFaceEndpoint(
14
  repo_id="Qwen/Qwen3-32B",
15
  provider="nebius",
16
  temperature=0.6,
17
- max_new_tokens=300,
18
- task="conversational"
19
  )
20
 
21
- chat_model = ChatHuggingFace(
22
- llm=model,
23
- repo_id="Qwen/Qwen3-32B",
24
- provider="nebius",
25
- temperature=0.6,
26
- max_new_tokens=300,
27
- task="conversational"
28
- )
29
 
30
  # --- Streamlit styles ---
31
  st.markdown("""
@@ -67,15 +64,15 @@ for i, subject in enumerate(subjects):
67
  st.session_state.selected_subject = subject
68
  st.session_state.message_history = [] # Reset chat on subject change
69
 
70
- # --- System Message ---
71
- system_prompt = f"""
 
72
  You are a highly knowledgeable data science mentor specialized in {st.session_state.selected_subject}.
73
  Your job is to guide a {experience.lower()} learner with clear, concise, and actionable advice.
74
  Explain concepts, best practices, and answer questions with patience and professionalism.
75
  If relevant, include example code, use-cases, or tips.
76
  """
77
- if not st.session_state.message_history:
78
- st.session_state.message_history.append(SystemMessage(content=system_prompt))
79
 
80
  # --- Chat Input ---
81
  user_question = st.text_input(f"💬 Ask your {st.session_state.selected_subject} question:")
 
4
  from langchain_community.llms import HuggingFaceEndpoint
5
  from langchain_core.messages import HumanMessage, SystemMessage, AIMessage
6
 
7
+ # --- Load API Token ---
8
+ hf_token = os.getenv("Data_science")
9
+ if not hf_token:
10
+ st.error("❌ Hugging Face token not found. Please set the 'Data_science' environment variable.")
11
+ st.stop()
12
 
 
13
  os.environ["HUGGINGFACEHUB_API_KEY"] = hf_token
14
  os.environ["HF_TOKEN"] = hf_token
15
 
16
+ # --- Load Hugging Face model (Qwen) ---
17
  model = HuggingFaceEndpoint(
18
  repo_id="Qwen/Qwen3-32B",
19
  provider="nebius",
20
  temperature=0.6,
21
+ max_new_tokens=500,
22
+ task="text-generation"
23
  )
24
 
25
+ chat_model = ChatHuggingFace(llm=model)
 
 
 
 
 
 
 
26
 
27
  # --- Streamlit styles ---
28
  st.markdown("""
 
64
  st.session_state.selected_subject = subject
65
  st.session_state.message_history = [] # Reset chat on subject change
66
 
67
+ # --- Set system message based on subject & experience ---
68
+ if not st.session_state.message_history:
69
+ system_prompt = f"""
70
  You are a highly knowledgeable data science mentor specialized in {st.session_state.selected_subject}.
71
  Your job is to guide a {experience.lower()} learner with clear, concise, and actionable advice.
72
  Explain concepts, best practices, and answer questions with patience and professionalism.
73
  If relevant, include example code, use-cases, or tips.
74
  """
75
+ st.session_state.message_history.append(SystemMessage(content=system_prompt.strip()))
 
76
 
77
  # --- Chat Input ---
78
  user_question = st.text_input(f"💬 Ask your {st.session_state.selected_subject} question:")