abanm commited on
Commit
f496ef8
·
verified ·
1 Parent(s): 6d9ff5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -16
app.py CHANGED
@@ -10,18 +10,13 @@ DUBS_PATH = "🐾" # Optional: Replace with an avatar path if needed
10
  # Streamlit Configuration
11
  st.set_page_config(page_title="Chatbot Test", page_icon="🤖", layout="centered")
12
 
13
- # Chat State
14
- if "messages" not in st.session_state:
15
- st.session_state["messages"] = []
16
-
17
- client = InferenceClient(SPACE_URL, token=HF_API_KEY)
18
-
19
  # Function to Fetch Response (Non-Streaming)
20
  def fetch_response(prompt_text, api_key):
21
  """
22
  Fetch full text response from the HF Inference Endpoint using the InferenceClient.
23
  Returns the generated text as a whole.
24
  """
 
25
 
26
  gen_kwargs = {
27
  "max_new_tokens": 512,
@@ -45,20 +40,14 @@ st.title("Chatbot Testing Interface")
45
  prompt = st.chat_input("Enter your message...")
46
 
47
  if prompt:
48
- # 1) Add the user's message to session state
49
- st.session_state["messages"].append({"role": "user", "content": prompt})
50
  st.chat_message("user").write(prompt)
51
 
52
- # 2) Build combined chat history for the model prompt
53
- chat_history = "".join(
54
- [f"<|{msg['role']}|>{msg['content']}<|end|>" for msg in st.session_state["messages"]]
55
- )
56
 
57
- # 3) Generate the response
58
  with st.chat_message("assistant", avatar=DUBS_PATH):
59
  with st.spinner("Dubs is thinking... Woof Woof! 🐾"):
60
  full_response = fetch_response(chat_history, HF_API_KEY)
61
  st.write(full_response)
62
-
63
- # 4) Add assistant response to the session state
64
- st.session_state["messages"].append({"role": "assistant", "content": full_response})
 
10
  # Streamlit Configuration
11
  st.set_page_config(page_title="Chatbot Test", page_icon="🤖", layout="centered")
12
 
 
 
 
 
 
 
13
  # Function to Fetch Response (Non-Streaming)
14
  def fetch_response(prompt_text, api_key):
15
  """
16
  Fetch full text response from the HF Inference Endpoint using the InferenceClient.
17
  Returns the generated text as a whole.
18
  """
19
+ client = InferenceClient(SPACE_URL, token=api_key)
20
 
21
  gen_kwargs = {
22
  "max_new_tokens": 512,
 
40
  prompt = st.chat_input("Enter your message...")
41
 
42
  if prompt:
43
+ # Display the user's message
 
44
  st.chat_message("user").write(prompt)
45
 
46
+ # Build the chat history (use prompt directly for stateless behavior)
47
+ chat_history = f"<|user|>{prompt}<|end|>"
 
 
48
 
49
+ # Generate the response
50
  with st.chat_message("assistant", avatar=DUBS_PATH):
51
  with st.spinner("Dubs is thinking... Woof Woof! 🐾"):
52
  full_response = fetch_response(chat_history, HF_API_KEY)
53
  st.write(full_response)