masadonline commited on
Commit
5a62060
Β·
verified Β·
1 Parent(s): f57c1dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -70,10 +70,10 @@ def fetch_latest_incoming_message(account_sid, auth_token, conversation_sid):
70
  return msg.body, msg.author, msg.index
71
  return None, None, None
72
 
73
- def send_twilio_message(account_sid, auth_token, conversation_sid, to, body):
74
  try:
75
  client = Client(account_sid, auth_token)
76
- message = client.conversations.v1.conversations(conversation_sid).messages.create(author=to, body=body)
77
  return message.sid
78
  except Exception as e:
79
  return str(e)
@@ -82,11 +82,18 @@ def send_twilio_message(account_sid, auth_token, conversation_sid, to, body):
82
  st.set_page_config(page_title="SMEHelpBot – WhatsApp Integration", layout="wide")
83
  st.title("πŸ“± SMEHelpBot + WhatsApp (via Twilio)")
84
 
85
- # Secrets and config
86
- account_sid = st.secrets.get("TWILIO_ACCOUNT_SID") or st.text_input("Twilio Account SID", "")
87
- auth_token = st.secrets.get("TWILIO_AUTH_TOKEN") or st.text_input("Twilio Auth Token", type="password")
88
- conversation_sid = st.text_input("Twilio Conversation SID", "")
89
- GROQ_API_KEY = st.secrets.get("GROQ_API_KEY") or st.text_input("GROQ API Key", type="password")
 
 
 
 
 
 
 
90
 
91
  if all([account_sid, auth_token, conversation_sid, GROQ_API_KEY]):
92
  os.environ["GROQ_API_KEY"] = GROQ_API_KEY
@@ -121,10 +128,10 @@ if all([account_sid, auth_token, conversation_sid, GROQ_API_KEY]):
121
  relevant_chunks = retrieve_chunks(question, index, embedding_model, text_chunks)
122
  context = "\n\n".join(relevant_chunks)
123
  answer = generate_answer_with_groq(question, context)
124
- send_twilio_message(account_sid, auth_token, conversation_sid, "system", answer)
125
  st.success("πŸ“€ Answer sent via WhatsApp!")
126
  st.markdown(f"### ✨ Answer:\n\n{answer}")
127
  else:
128
  st.warning("No new messages from users found.")
129
  else:
130
- st.warning("Please fill all required credentials.")
 
70
  return msg.body, msg.author, msg.index
71
  return None, None, None
72
 
73
+ def send_twilio_message(account_sid, auth_token, conversation_sid, body):
74
  try:
75
  client = Client(account_sid, auth_token)
76
+ message = client.conversations.v1.conversations(conversation_sid).messages.create(author="system", body=body)
77
  return message.sid
78
  except Exception as e:
79
  return str(e)
 
82
  st.set_page_config(page_title="SMEHelpBot – WhatsApp Integration", layout="wide")
83
  st.title("πŸ“± SMEHelpBot + WhatsApp (via Twilio)")
84
 
85
+ # Load from Hugging Face secrets
86
+ account_sid = st.secrets.get("TWILIO_SID")
87
+ auth_token = st.secrets.get("TWILIO_TOKEN")
88
+ conversation_sid = "CH0401ce390b374780b3eaded677d882b0"
89
+ GROQ_API_KEY = st.secrets.get("GROQ_API_KEY")
90
+
91
+ # Fallback for testing
92
+ if not all([account_sid, auth_token, GROQ_API_KEY]):
93
+ st.warning("⚠️ Some secrets not found. Please enter missing credentials below:")
94
+ account_sid = st.text_input("Twilio SID", value=account_sid or "")
95
+ auth_token = st.text_input("Twilio Auth Token", type="password", value=auth_token or "")
96
+ GROQ_API_KEY = st.text_input("GROQ API Key", type="password", value=GROQ_API_KEY or "")
97
 
98
  if all([account_sid, auth_token, conversation_sid, GROQ_API_KEY]):
99
  os.environ["GROQ_API_KEY"] = GROQ_API_KEY
 
128
  relevant_chunks = retrieve_chunks(question, index, embedding_model, text_chunks)
129
  context = "\n\n".join(relevant_chunks)
130
  answer = generate_answer_with_groq(question, context)
131
+ send_twilio_message(account_sid, auth_token, conversation_sid, answer)
132
  st.success("πŸ“€ Answer sent via WhatsApp!")
133
  st.markdown(f"### ✨ Answer:\n\n{answer}")
134
  else:
135
  st.warning("No new messages from users found.")
136
  else:
137
+ st.warning("❗ Please provide all required credentials.")