muhammadsalmanalfaridzi commited on
Commit
9c0f774
·
verified ·
1 Parent(s): 0cb076f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -30
app.py CHANGED
@@ -24,18 +24,8 @@ client = None
24
  def load_llm():
25
  # Ensure you have the API Key set in your environment or via input
26
  api_key = os.getenv("CEREBRAS_API_KEY")
27
- if not api_key:
28
- api_key = st.text_input("Enter your Cerebras API key:")
29
- if api_key:
30
- llm = Cerebras(model="llama-3.3-70b", api_key=api_key)
31
- return llm
32
- else:
33
- st.error("API Key is required.")
34
- return None
35
-
36
- # Load llm at the beginning of the session
37
- if "llm" not in st.session_state:
38
- st.session_state.llm = load_llm()
39
 
40
  def reset_chat():
41
  st.session_state.messages = []
@@ -46,8 +36,6 @@ def display_excel(file):
46
  st.markdown("### Excel Preview")
47
  # Read the Excel file
48
  df = pd.read_excel(file)
49
- # Attempt to fix mixed-type column errors
50
- #df = df.apply(pd.to_numeric, errors='coerce') # Convert columns to numeric where possible
51
  # Display the dataframe
52
  st.dataframe(df)
53
 
@@ -149,23 +137,18 @@ if prompt := st.chat_input("What's up?"):
149
  with st.chat_message("assistant"):
150
  message_placeholder = st.empty()
151
  full_response = ""
 
 
 
 
 
 
 
152
 
153
- # Ensure llm is loaded
154
- if st.session_state.llm:
155
- # Using Cerebras stream_chat for streaming response
156
- messages = [
157
- ChatMessage(role="user", content=prompt)
158
- ]
159
 
160
- response = st.session_state.llm.stream_chat(messages)
161
- for r in response:
162
- full_response += r.delta
163
- message_placeholder.markdown(full_response + "▌")
164
-
165
- message_placeholder.markdown(full_response)
166
-
167
- else:
168
- st.error("LLM model is not initialized correctly.")
169
 
170
  # Add assistant response to chat history
171
- st.session_state.messages.append({"role": "assistant", "content": full_response})
 
24
  def load_llm():
25
  # Ensure you have the API Key set in your environment or via input
26
  api_key = os.getenv("CEREBRAS_API_KEY")
27
+ llm = Cerebras(model="llama-3.3-70b", api_key=api_key)
28
+ return llm
 
 
 
 
 
 
 
 
 
 
29
 
30
  def reset_chat():
31
  st.session_state.messages = []
 
36
  st.markdown("### Excel Preview")
37
  # Read the Excel file
38
  df = pd.read_excel(file)
 
 
39
  # Display the dataframe
40
  st.dataframe(df)
41
 
 
137
  with st.chat_message("assistant"):
138
  message_placeholder = st.empty()
139
  full_response = ""
140
+
141
+ # Simulate stream of response with milliseconds delay
142
+ streaming_response = query_engine.query(prompt)
143
+
144
+ for chunk in streaming_response.response_gen:
145
+ full_response += chunk
146
+ message_placeholder.markdown(full_response + "▌")
147
 
148
+ # full_response = query_engine.query(prompt)
 
 
 
 
 
149
 
150
+ message_placeholder.markdown(full_response)
151
+ # st.session_state.context = ctx
 
 
 
 
 
 
 
152
 
153
  # Add assistant response to chat history
154
+ st.session_state.messages.append({"role": "assistant", "content": full_response})