abanm commited on
Commit
2e17d47
·
verified ·
1 Parent(s): 1068688

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -22
app.py CHANGED
@@ -6,19 +6,6 @@ import json
6
  SPACE_URL = "https://abanm-dubs.hf.space/api/generate"
7
  API_KEY = "s3cr3t_k3y" # Replace with your actual API key
8
 
9
-
10
-
11
- # Streamlit Configurations (must come first)
12
- st.set_page_config(page_title="💬 DUBSChat", layout="centered")
13
-
14
-
15
- # Sidebar Configuration
16
- with st.sidebar:
17
- Dubs_Key = st.text_input("Enter your Dubs Key", key="chatbot_api_key", type="password")
18
- #st.markdown("### DUBS Settings")
19
- st.markdown("""Dubs Recall""")
20
- st.markdown("""Comming Soon!""")
21
-
22
  def call_api(message):
23
  """
24
  Calls the backend API with the user's input using streaming.
@@ -30,7 +17,7 @@ def call_api(message):
30
  str: Streamed partial response from the backend API.
31
  """
32
  headers = {
33
- "Authorization": f"Bearer {Dubs_Key}",
34
  "Content-Type": "application/json",
35
  }
36
  payload = {"prompt": message} # Match the API's expected input key
@@ -55,16 +42,21 @@ def call_api(message):
55
  except requests.exceptions.RequestException as e:
56
  yield f"Error: {str(e)}"
57
 
 
 
58
 
59
-
60
-
 
 
 
61
 
62
  # Chat History Initialization
63
  if "messages" not in st.session_state:
64
  st.session_state["messages"] = [{"role": "assistant", "content": "Hello! How can I assist you today?"}]
65
 
66
  # Main Chat UI
67
- st.title("DUBS v.0.0.3")
68
  st.markdown("Empowering you with a Sustainable AI")
69
 
70
  # Chat Display
@@ -83,11 +75,17 @@ if prompt := st.chat_input():
83
  # Display a placeholder for the assistant's response
84
  assistant_message_placeholder = st.chat_message("assistant").empty()
85
 
86
- with st.spinner("Translating to Dubs language (Woof Woof!)"):
87
- bot_response = ""
88
- for partial_response in call_api(prompt):
89
- bot_response += partial_response
90
- assistant_message_placeholder.write(bot_response) # Update incrementally
 
 
 
 
 
 
91
 
92
  # Append the final assistant's response to the chat history
93
  st.session_state["messages"].append({"role": "assistant", "content": bot_response})
 
6
  SPACE_URL = "https://abanm-dubs.hf.space/api/generate"
7
  API_KEY = "s3cr3t_k3y" # Replace with your actual API key
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def call_api(message):
10
  """
11
  Calls the backend API with the user's input using streaming.
 
17
  str: Streamed partial response from the backend API.
18
  """
19
  headers = {
20
+ "Authorization": f"Bearer {API_KEY}",
21
  "Content-Type": "application/json",
22
  }
23
  payload = {"prompt": message} # Match the API's expected input key
 
42
  except requests.exceptions.RequestException as e:
43
  yield f"Error: {str(e)}"
44
 
45
+ # Streamlit Configurations (must come first)
46
+ st.set_page_config(page_title="💬 DUBSChat", layout="centered")
47
 
48
+ # Sidebar Configuration
49
+ with st.sidebar:
50
+ st.markdown("### DUBS Settings")
51
+ st.markdown("""Other Features.""")
52
+ st.markdown("""Comming Soon!""")
53
 
54
  # Chat History Initialization
55
  if "messages" not in st.session_state:
56
  st.session_state["messages"] = [{"role": "assistant", "content": "Hello! How can I assist you today?"}]
57
 
58
  # Main Chat UI
59
+ st.title("DubsChat")
60
  st.markdown("Empowering you with a Sustainable AI")
61
 
62
  # Chat Display
 
75
  # Display a placeholder for the assistant's response
76
  assistant_message_placeholder = st.chat_message("assistant").empty()
77
 
78
+ bot_response = ""
79
+ first_chunk = True
80
+
81
+ for partial_response in call_api(prompt):
82
+ bot_response += partial_response
83
+
84
+ if first_chunk:
85
+ first_chunk = False
86
+ st.spinner("Translating from Dubs language (Woof Woof!)")
87
+
88
+ assistant_message_placeholder.write(bot_response) # Update incrementally
89
 
90
  # Append the final assistant's response to the chat history
91
  st.session_state["messages"].append({"role": "assistant", "content": bot_response})