@@ -29,7 +29,31 @@ def send_photo_to_api(files: Dict):
2929 if r .status_code == 201 :
3030 telegram_bot .info (f"File sucessfully uploaded: { r .text } " )
3131 except Exception as e :
32- telegram_bot .error (f"There is an error when send the file: { e } ." )
32+ telegram_bot .error (f"There was an error sending the file: { e } ." )
33+
34+
35+ def keyboard ():
36+ keyboard = [
37+ [
38+ InlineKeyboardButton ("Yes!!!" , callback_data = "yes" ),
39+ InlineKeyboardButton ("No" , callback_data = "no" ),
40+ ],
41+ ]
42+
43+ reply_markup = InlineKeyboardMarkup (keyboard )
44+ return reply_markup
45+
46+
47+ def keyboard_start ():
48+ keyboard = [
49+ [
50+ InlineKeyboardButton ("Yes!!!" , callback_data = "YES" ),
51+ InlineKeyboardButton ("No" , callback_data = "NO" ),
52+ ],
53+ ]
54+
55+ reply_markup = InlineKeyboardMarkup (keyboard )
56+ return reply_markup
3357
3458
3559def start (update : Update , context : CallbackContext ) -> None :
@@ -44,9 +68,11 @@ def start(update: Update, context: CallbackContext) -> None:
4468 Outputs:
4569 None
4670 """
71+ reply_markup = keyboard_start ()
4772 context .bot .send_message (
4873 chat_id = update .effective_chat .id ,
49- text = "Welcome to mairror! Do you need to guess your age?" ,
74+ text = "Welcome to mairror! Do you want me to guess your age?" ,
75+ reply_markup = reply_markup ,
5076 )
5177
5278
@@ -62,7 +88,8 @@ def text(update: Update, context: CallbackContext) -> None:
6288 None
6389 """
6490 context .bot .send_message (
65- chat_id = update .effective_chat .id , text = "Sorry, I didn't understand you."
91+ chat_id = update .effective_chat .id ,
92+ text = "Sorry, I didn't understand you. Please send me a pic." ,
6693 )
6794
6895
@@ -135,19 +162,7 @@ def predict(image):
135162 telegram_bot .error (f"Error querying the API: { r .text } ." )
136163 return "There was an error predicting your image."
137164 except Exception as e :
138- telegram_bot .error (f"There is an error when get tyhe prediction: { e } ." )
139-
140-
141- def keyboard ():
142- keyboard = [
143- [
144- InlineKeyboardButton ("Yes!!!" , callback_data = "yes" ),
145- InlineKeyboardButton ("No" , callback_data = "no" ),
146- ],
147- ]
148-
149- reply_markup = InlineKeyboardMarkup (keyboard )
150- return reply_markup
165+ telegram_bot .error (f"There is an error making the prediction: { e } ." )
151166
152167
153168def button (update : Update , context : CallbackContext ) -> None :
@@ -163,11 +178,18 @@ def button(update: Update, context: CallbackContext) -> None:
163178 """
164179 query = update .callback_query
165180 query .answer ()
166- if query .data == "yes" :
181+ answer = query .data
182+ if answer == "yes" :
167183 query .edit_message_text (text = "I'm a great guesser!" )
184+ elif answer == "YES" :
185+ query .edit_message_text (
186+ text = "To start please send me a pic of yourself and I will try to guess your age and gender."
187+ )
188+ elif answer == "NO" :
189+ query .edit_message_text (text = "No problem, you can come back whenever you want." )
168190 else :
169191 query .edit_message_text (
170- text = "Sorry, I'll do the best of me . I need more images to improve the prediction ."
192+ text = "Sorry, I'll do my best the next time :( . I need more images to improve my predictions ."
171193 )
172194
173195
@@ -205,4 +227,4 @@ def photo(update: Update, context: CallbackContext) -> None:
205227 disable_web_page_preview = True ,
206228 )
207229 reply_markup = keyboard ()
208- update .message .reply_text ("Have I guessed your age?" , reply_markup = reply_markup )
230+ update .message .reply_text ("Did I guess your age?" , reply_markup = reply_markup )
0 commit comments