Update app.py
Browse files
app.py
CHANGED
|
@@ -9,26 +9,26 @@ api_base=os.getenv("OPENAI_API_BASE")
|
|
| 9 |
llm=ChatOpenAI(model_name="google/gemma-3n-e2b-it:free",temperature=0.7)
|
| 10 |
# Streamlit UI
|
| 11 |
st.set_page_config(page_title="Chatbot", layout="centered")
|
| 12 |
-
st.title("💬 Chat with
|
| 13 |
|
| 14 |
# Chat history session state
|
| 15 |
if "history" not in st.session_state:
|
| 16 |
st.session_state.history = []
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
user_input = st.text_input("Ask me anything:", key="input")
|
| 20 |
|
| 21 |
# Handle input
|
| 22 |
if user_input:
|
| 23 |
-
#
|
| 24 |
st.session_state.history.append(("You", user_input))
|
| 25 |
|
| 26 |
-
# Get response from
|
| 27 |
response = llm.invoke(user_input)
|
| 28 |
|
| 29 |
-
#
|
| 30 |
st.session_state.history.append(("Bot", response.content))
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
st.markdown(f"**{sender}:** {msg}")
|
|
|
|
| 9 |
llm=ChatOpenAI(model_name="google/gemma-3n-e2b-it:free",temperature=0.7)
|
| 10 |
# Streamlit UI
|
| 11 |
st.set_page_config(page_title="Chatbot", layout="centered")
|
| 12 |
+
st.title("💬 Chat with me")
|
| 13 |
|
| 14 |
# Chat history session state
|
| 15 |
if "history" not in st.session_state:
|
| 16 |
st.session_state.history = []
|
| 17 |
|
| 18 |
+
|
| 19 |
+
#Then place the prompt box at the bottom
|
| 20 |
user_input = st.text_input("Ask me anything:", key="input")
|
| 21 |
|
| 22 |
# Handle input
|
| 23 |
if user_input:
|
| 24 |
+
# Add user message to history
|
| 25 |
st.session_state.history.append(("You", user_input))
|
| 26 |
|
| 27 |
+
# Get response from the model
|
| 28 |
response = llm.invoke(user_input)
|
| 29 |
|
| 30 |
+
# Add bot response to history
|
| 31 |
st.session_state.history.append(("Bot", response.content))
|
| 32 |
|
| 33 |
+
# Clear the input box after submission
|
| 34 |
+
st.experimental_rerun()
|
|
|