masadonline commited on
Commit
b036db9
Β·
verified Β·
1 Parent(s): 61a6fd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -11,7 +11,13 @@ import docx
11
  from groq import Groq
12
  import PyPDF2
13
  import requests
14
- from streamlit_extras.st_autorefresh import st_autorefresh
 
 
 
 
 
 
15
 
16
  # --- Document Loaders ---
17
  def extract_text_from_pdf(pdf_path):
@@ -101,9 +107,6 @@ def send_twilio_message(account_sid, auth_token, conversation_sid, body):
101
  # --- Streamlit UI ---
102
  st.set_page_config(page_title="Quasa – A Smart WhatsApp Chatbot", layout="wide")
103
 
104
- # Auto-refresh every 10 seconds
105
- st_autorefresh(interval=10 * 1000, key="auto_refresh")
106
-
107
  # Styling
108
  st.markdown("""
109
  <style>
@@ -136,6 +139,7 @@ account_sid = st.secrets.get("TWILIO_SID")
136
  auth_token = st.secrets.get("TWILIO_TOKEN")
137
  GROQ_API_KEY = st.secrets.get("GROQ_API_KEY")
138
 
 
139
  if not all([account_sid, auth_token, GROQ_API_KEY]):
140
  st.warning("⚠️ Some secrets are missing. Please provide them manually:")
141
  account_sid = st.text_input("Twilio SID", value=account_sid or "")
@@ -185,6 +189,6 @@ if all([account_sid, auth_token, GROQ_API_KEY, conversation_sid]):
185
  st.success("πŸ“€ Answer sent back to user on WhatsApp!")
186
  st.markdown(f"### ✨ Answer:\n\n{answer}")
187
  else:
188
- st.info("πŸ”„ No new messages yet...")
189
  else:
190
  st.warning("❗ Please provide all required credentials and conversation SID.")
 
11
  from groq import Groq
12
  import PyPDF2
13
  import requests
14
+
15
+ # --- Auto-refresh every 10 seconds ---
16
+ if "last_refresh" not in st.session_state:
17
+ st.session_state.last_refresh = time.time()
18
+ elif time.time() - st.session_state.last_refresh > 10:
19
+ st.session_state.last_refresh = time.time()
20
+ st.experimental_rerun()
21
 
22
  # --- Document Loaders ---
23
  def extract_text_from_pdf(pdf_path):
 
107
  # --- Streamlit UI ---
108
  st.set_page_config(page_title="Quasa – A Smart WhatsApp Chatbot", layout="wide")
109
 
 
 
 
110
  # Styling
111
  st.markdown("""
112
  <style>
 
139
  auth_token = st.secrets.get("TWILIO_TOKEN")
140
  GROQ_API_KEY = st.secrets.get("GROQ_API_KEY")
141
 
142
+ # Allow user input fallback
143
  if not all([account_sid, auth_token, GROQ_API_KEY]):
144
  st.warning("⚠️ Some secrets are missing. Please provide them manually:")
145
  account_sid = st.text_input("Twilio SID", value=account_sid or "")
 
189
  st.success("πŸ“€ Answer sent back to user on WhatsApp!")
190
  st.markdown(f"### ✨ Answer:\n\n{answer}")
191
  else:
192
+ st.warning("No new messages found.")
193
  else:
194
  st.warning("❗ Please provide all required credentials and conversation SID.")