Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,6 +16,10 @@ from io import StringIO
|
|
16 |
from pdfminer.high_level import extract_text_to_fp
|
17 |
from pdfminer.layout import LAParams
|
18 |
|
|
|
|
|
|
|
|
|
19 |
# --- PDF Extraction ---
|
20 |
def extract_text_from_pdf(pdf_path):
|
21 |
output_string = StringIO()
|
@@ -159,22 +163,25 @@ def start_conversation_monitor(client, index, embed_model, text_chunks):
|
|
159 |
time.sleep(5)
|
160 |
|
161 |
def poll_new_conversations():
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
178 |
|
179 |
threading.Thread(target=poll_new_conversations, daemon=True).start()
|
180 |
|
@@ -199,4 +206,4 @@ if all([account_sid, auth_token, GROQ_API_KEY]):
|
|
199 |
st.success("π’ Monitoring new WhatsApp conversations...")
|
200 |
index, model, chunks = setup_knowledge_base()
|
201 |
threading.Thread(target=start_conversation_monitor, args=(client, index, model, chunks), daemon=True).start()
|
202 |
-
st.info("β³ Waiting for new messages...")
|
|
|
16 |
from pdfminer.high_level import extract_text_to_fp
|
17 |
from pdfminer.layout import LAParams
|
18 |
|
19 |
+
import datetime
|
20 |
+
|
21 |
+
APP_START_TIME = datetime.datetime.utcnow()
|
22 |
+
|
23 |
# --- PDF Extraction ---
|
24 |
def extract_text_from_pdf(pdf_path):
|
25 |
output_string = StringIO()
|
|
|
163 |
time.sleep(5)
|
164 |
|
165 |
def poll_new_conversations():
|
166 |
+
print("β‘οΈ Monitoring for new WhatsApp conversations...")
|
167 |
+
while True:
|
168 |
+
try:
|
169 |
+
conversations = client.conversations.v1.conversations.list(limit=20)
|
170 |
+
for convo in conversations:
|
171 |
+
convo_full = client.conversations.v1.conversations(convo.sid).fetch()
|
172 |
+
# convo_full.date_created should be available
|
173 |
+
if convo.sid not in processed_convos and convo_full.date_created > APP_START_TIME:
|
174 |
+
participants = client.conversations.v1.conversations(convo.sid).participants.list()
|
175 |
+
for p in participants:
|
176 |
+
address = p.messaging_binding.get("address", "") if p.messaging_binding else ""
|
177 |
+
if address.startswith("whatsapp:"):
|
178 |
+
print(f"π New WhatsApp convo found: {convo.sid}")
|
179 |
+
processed_convos.add(convo.sid)
|
180 |
+
threading.Thread(target=poll_conversation, args=(convo.sid,), daemon=True).start()
|
181 |
+
except Exception as e:
|
182 |
+
print("β Error polling conversations:", e)
|
183 |
+
time.sleep(5)
|
184 |
+
|
185 |
|
186 |
threading.Thread(target=poll_new_conversations, daemon=True).start()
|
187 |
|
|
|
206 |
st.success("π’ Monitoring new WhatsApp conversations...")
|
207 |
index, model, chunks = setup_knowledge_base()
|
208 |
threading.Thread(target=start_conversation_monitor, args=(client, index, model, chunks), daemon=True).start()
|
209 |
+
st.info("β³ Waiting for new messages...")
|