Enoch1359 commited on
Commit
4b6b65b
·
verified ·
1 Parent(s): 7a05181

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
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 LLM")
13
 
14
  # Chat history session state
15
  if "history" not in st.session_state:
16
  st.session_state.history = []
17
 
18
- # Prompt input
 
19
  user_input = st.text_input("Ask me anything:", key="input")
20
 
21
  # Handle input
22
  if user_input:
23
- # Append user message
24
  st.session_state.history.append(("You", user_input))
25
 
26
- # Get response from LLM
27
  response = llm.invoke(user_input)
28
 
29
- # Append bot message
30
  st.session_state.history.append(("Bot", response.content))
31
 
32
- # Display conversation
33
- for sender, msg in st.session_state.history:
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()