Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,36 +72,53 @@ elif st.session_state.page == "python":
|
|
| 72 |
# max_new_tokens=100,
|
| 73 |
# task="conversational"
|
| 74 |
# )
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
#
|
| 100 |
-
|
| 101 |
-
#
|
| 102 |
-
|
| 103 |
-
#
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
st.button("⬅️ Back to Home", on_click=lambda: switch_page("home"))
|
| 106 |
# Here you can load your Python LLM and chat interface
|
| 107 |
|
|
@@ -135,7 +152,7 @@ elif st.session_state.page == "sql":
|
|
| 135 |
|
| 136 |
# Initialize chat history
|
| 137 |
if "messages" not in st.session_state:
|
| 138 |
-
st.session_state.messages = [SystemMessage(content="Answer clearly like a technical SQL
|
| 139 |
|
| 140 |
# User input
|
| 141 |
user_input = st.text_input("💡 Ask your SQL interview question:", placeholder="e.g., give me 10 SQL interview questions with answers")
|
|
|
|
| 72 |
# max_new_tokens=100,
|
| 73 |
# task="conversational"
|
| 74 |
# )
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
gemma_model = HuggingFaceEndpoint(
|
| 78 |
+
repo_id="google/gemma-3-27b-it",
|
| 79 |
+
temperature=0.7,
|
| 80 |
+
max_new_tokens=512,
|
| 81 |
+
task="conversational",
|
| 82 |
+
huggingfacehub_api_token=hf_token,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
chat_gemma = ChatHuggingFace(
|
| 86 |
+
llm=gemma_model,
|
| 87 |
+
repo_id="google/gemma-3-27b-it",
|
| 88 |
+
temperature=0.7,
|
| 89 |
+
max_new_tokens=512,
|
| 90 |
+
task="conversational",
|
| 91 |
+
)
|
| 92 |
+
# Initialize session state for chat history
|
| 93 |
+
if "messages" not in st.session_state:
|
| 94 |
+
st.session_state.messages = [
|
| 95 |
+
SystemMessage(content="Answer like a 10 year experinced Python developer")
|
| 96 |
+
]
|
| 97 |
+
|
| 98 |
+
def generate_response(user_input):
|
| 99 |
+
# Append user message
|
| 100 |
+
st.session_state.messages.append(HumanMessage(content=user_input))
|
| 101 |
+
# Invoke the model
|
| 102 |
+
response = deepseek.invoke(st.session_state.messages)
|
| 103 |
+
# Append AI response
|
| 104 |
+
st.session_state.messages.append(AIMessage(content=response))
|
| 105 |
+
return response
|
| 106 |
+
|
| 107 |
+
# User input
|
| 108 |
+
user_input = st.text_input("Ask a question about Python:")
|
| 109 |
+
|
| 110 |
+
if user_input:
|
| 111 |
+
with st.spinner("Getting answer..."):
|
| 112 |
+
answer = generate_response(user_input)
|
| 113 |
+
st.markdown(f"**Answer:** {answer}")
|
| 114 |
+
|
| 115 |
+
# Display chat history
|
| 116 |
+
if st.session_state.messages:
|
| 117 |
+
for msg in st.session_state.messages[1:]: # skip initial SystemMessage
|
| 118 |
+
if isinstance(msg, HumanMessage):
|
| 119 |
+
st.markdown(f"**You:** {msg.content}")
|
| 120 |
+
elif isinstance(msg, AIMessage):
|
| 121 |
+
st.markdown(f"**Bot:** {msg.content}")
|
| 122 |
st.button("⬅️ Back to Home", on_click=lambda: switch_page("home"))
|
| 123 |
# Here you can load your Python LLM and chat interface
|
| 124 |
|
|
|
|
| 152 |
|
| 153 |
# Initialize chat history
|
| 154 |
if "messages" not in st.session_state:
|
| 155 |
+
st.session_state.messages = [SystemMessage(content="Answer clearly like a technical 10 year experienced person in SQL .")]
|
| 156 |
|
| 157 |
# User input
|
| 158 |
user_input = st.text_input("💡 Ask your SQL interview question:", placeholder="e.g., give me 10 SQL interview questions with answers")
|