Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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,
|
74 |
try:
|
75 |
client = Client(account_sid, auth_token)
|
76 |
-
message = client.conversations.v1.conversations(conversation_sid).messages.create(author=
|
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 |
-
#
|
86 |
-
account_sid = st.secrets.get("
|
87 |
-
auth_token = st.secrets.get("
|
88 |
-
conversation_sid =
|
89 |
-
GROQ_API_KEY = st.secrets.get("GROQ_API_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
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
|
|
|
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.")
|