EricGEGE commited on
Commit
db0b299
·
verified ·
1 Parent(s): 9f58f07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import numpy as np
2
  import pandas as pd
3
-
4
  from sentence_transformers import SentenceTransformer
5
 
6
  from sklearn.metrics import DistanceMetric
@@ -13,6 +13,9 @@ import gradio as gr
13
  # move_cache()
14
  from telegram import Bot
15
 
 
 
 
16
  token = '7370905765:AAHvmlw68cW7RxWzsJE1yxTzgf3xQFiokDo'
17
  chat_id = '7431171535'
18
  pd.set_option('display.max_colwidth', None)
@@ -23,9 +26,12 @@ model = SentenceTransformer("all-MiniLM-L6-v2")
23
  # file_name = 'questions.txt'
24
 
25
  def send_telegram_message(token, chat_id, message):
26
- bot = Bot(token=token)
27
- bot.send_message(chat_id=chat_id, text=message)
28
- print("Message sent successfully.")
 
 
 
29
 
30
 
31
  def savevectorstore():
@@ -79,7 +85,10 @@ def rag_chain(question,name):
79
  # with open('questions.txt', 'a',encoding='utf-8') as file:
80
  # file.write(f"\n\n{question}\n\n{country}\n\n{whatsapp}\n\n{name}||{sales}||{profit}||{product}")
81
  message = f"{name}\n\n{question}\n\n{ans}"
82
- send_telegram_message(token, chat_id, message)
 
 
 
83
  return que,ans
84
  # rag_chain('I am very hungry.')
85
 
 
1
  import numpy as np
2
  import pandas as pd
3
+ import logging
4
  from sentence_transformers import SentenceTransformer
5
 
6
  from sklearn.metrics import DistanceMetric
 
13
  # move_cache()
14
  from telegram import Bot
15
 
16
+ logging.basicConfig(level=logging.INFO)
17
+ logger = logging.getLogger(__name__)
18
+
19
  token = '7370905765:AAHvmlw68cW7RxWzsJE1yxTzgf3xQFiokDo'
20
  chat_id = '7431171535'
21
  pd.set_option('display.max_colwidth', None)
 
26
  # file_name = 'questions.txt'
27
 
28
  def send_telegram_message(token, chat_id, message):
29
+ try:
30
+ bot = Bot(token=token)
31
+ bot.send_message(chat_id=chat_id, text=message)
32
+ logger.info("Message sent successfully.")
33
+ except TelegramError as e:
34
+ logger.error(f"Failed to send message: {e}")
35
 
36
 
37
  def savevectorstore():
 
85
  # with open('questions.txt', 'a',encoding='utf-8') as file:
86
  # file.write(f"\n\n{question}\n\n{country}\n\n{whatsapp}\n\n{name}||{sales}||{profit}||{product}")
87
  message = f"{name}\n\n{question}\n\n{ans}"
88
+ if not token or not chat_id:
89
+ logger.error("Please set the TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID environment variables.")
90
+ else:
91
+ send_telegram_message(token, chat_id, message)
92
  return que,ans
93
  # rag_chain('I am very hungry.')
94