Anshini commited on
Commit
6b7c40c
·
verified ·
1 Parent(s): c18184f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -53
app.py CHANGED
@@ -49,59 +49,59 @@ if st.session_state.page == "home":
49
  # Example domain-specific chatbot page
50
  elif st.session_state.page == "python":
51
  st.title("Python Chatbot 🐍")
52
- hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN") or os.getenv("HF_TOKEN")
53
- if not hf_token:
54
- st.error("Please add your Hugging Face API token to Secrets (HUGGINGFACEHUB_API_TOKEN or HF_TOKEN).")
55
- st.stop()
56
-
57
- # Setup the LangChain HuggingFaceEndpoint and ChatHuggingFace LLM
58
- deep_seek_model = HuggingFaceEndpoint(
59
- repo_id="deepseek-ai/DeepSeek-R1",
60
- # provider = 'nebius'
61
- temperature=0.7,
62
- max_new_tokens=100,
63
- task="conversational",
64
- huggingfacehub_api_token=hf_token,
65
- )
66
-
67
- deepseek = ChatHuggingFace(
68
- llm=deep_seek_model,
69
- repo_id="deepseek-ai/DeepSeek-R1",
70
- # provider="nebius",
71
- temperature=0.7,
72
- max_new_tokens=100,
73
- task="conversational"
74
- )
75
- # Initialize session state for chat history
76
- if "messages" not in st.session_state:
77
- st.session_state.messages = [
78
- SystemMessage(content="Answer like a 10 year experinced Python developer")
79
- ]
80
-
81
- def generate_response(user_input):
82
- # Append user message
83
- st.session_state.messages.append(HumanMessage(content=user_input))
84
- # Invoke the model
85
- response = deepseek.invoke(st.session_state.messages)
86
- # Append AI response
87
- st.session_state.messages.append(AIMessage(content=response))
88
- return response
89
-
90
- # User input
91
- user_input = st.text_input("Ask a question about Python:")
92
-
93
- if user_input:
94
- with st.spinner("Getting answer..."):
95
- answer = generate_response(user_input)
96
- st.markdown(f"**Answer:** {answer}")
97
-
98
- # Display chat history
99
- if st.session_state.messages:
100
- for msg in st.session_state.messages[1:]: # skip initial SystemMessage
101
- if isinstance(msg, HumanMessage):
102
- st.markdown(f"**You:** {msg.content}")
103
- elif isinstance(msg, AIMessage):
104
- st.markdown(f"**Bot:** {msg.content}")
105
  st.button("⬅️ Back to Home", on_click=lambda: switch_page("home"))
106
  # Here you can load your Python LLM and chat interface
107
 
 
49
  # Example domain-specific chatbot page
50
  elif st.session_state.page == "python":
51
  st.title("Python Chatbot 🐍")
52
+ # hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN") or os.getenv("HF_TOKEN")
53
+ # if not hf_token:
54
+ # st.error("Please add your Hugging Face API token to Secrets (HUGGINGFACEHUB_API_TOKEN or HF_TOKEN).")
55
+ # st.stop()
56
+
57
+ # # Setup the LangChain HuggingFaceEndpoint and ChatHuggingFace LLM
58
+ # deep_seek_model = HuggingFaceEndpoint(
59
+ # repo_id="deepseek-ai/DeepSeek-R1",
60
+ # # provider = 'nebius'
61
+ # temperature=0.7,
62
+ # max_new_tokens=100,
63
+ # task="conversational",
64
+ # huggingfacehub_api_token=hf_token,
65
+ # )
66
+
67
+ # deepseek = ChatHuggingFace(
68
+ # llm=deep_seek_model,
69
+ # repo_id="deepseek-ai/DeepSeek-R1",
70
+ # # provider="nebius",
71
+ # temperature=0.7,
72
+ # max_new_tokens=100,
73
+ # task="conversational"
74
+ # )
75
+ # # Initialize session state for chat history
76
+ # if "messages" not in st.session_state:
77
+ # st.session_state.messages = [
78
+ # SystemMessage(content="Answer like a 10 year experinced Python developer")
79
+ # ]
80
+
81
+ # def generate_response(user_input):
82
+ # # Append user message
83
+ # st.session_state.messages.append(HumanMessage(content=user_input))
84
+ # # Invoke the model
85
+ # response = deepseek.invoke(st.session_state.messages)
86
+ # # Append AI response
87
+ # st.session_state.messages.append(AIMessage(content=response))
88
+ # return response
89
+
90
+ # # User input
91
+ # user_input = st.text_input("Ask a question about Python:")
92
+
93
+ # if user_input:
94
+ # with st.spinner("Getting answer..."):
95
+ # answer = generate_response(user_input)
96
+ # st.markdown(f"**Answer:** {answer}")
97
+
98
+ # # Display chat history
99
+ # if st.session_state.messages:
100
+ # for msg in st.session_state.messages[1:]: # skip initial SystemMessage
101
+ # if isinstance(msg, HumanMessage):
102
+ # st.markdown(f"**You:** {msg.content}")
103
+ # elif isinstance(msg, AIMessage):
104
+ # st.markdown(f"**Bot:** {msg.content}")
105
  st.button("⬅️ Back to Home", on_click=lambda: switch_page("home"))
106
  # Here you can load your Python LLM and chat interface
107