Anoar2025 commited on
Commit
aa76d90
ยท
verified ยท
1 Parent(s): ee977b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -16
app.py CHANGED
@@ -24,8 +24,6 @@ from typing import Dict, Optional, List, Tuple
24
 
25
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
26
  # ๐Ÿ”ง ุญู„ ZeroGPU: ุฏุงู„ุฉ ูˆู‡ู…ูŠุฉ ู„ุฅุฑุถุงุก ู†ุธุงู… Hugging Face Spaces
27
- # ู‡ุฐุง ุงู„ุญู„ ุถุฑูˆุฑูŠ ู„ุฃู† Hugging Face ูŠูุฑุถ ZeroGPU ุนู„ู‰ ุงู„ุญุณุงุจุงุช ุงู„ู…ุฌุงู†ูŠุฉ
28
- # ูˆู„ุง ูŠุณู…ุญ ุจู€ CPU basic. ุงู„ุฏุงู„ุฉ ู„ุง ุชุณุชุฎุฏู… GPU ูุนู„ูŠุงู‹.
29
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
30
  try:
31
  import spaces
@@ -34,10 +32,7 @@ try:
34
  def _warmup_gpu():
35
  """ุฏุงู„ุฉ ูˆู‡ู…ูŠุฉ ูู‚ุท ู„ุฅุฑุถุงุก ู†ุธุงู… ZeroGPU. ู„ุง ุชุณุชุฎุฏู… GPU ูุนู„ูŠุงู‹."""
36
  return "ok"
37
-
38
- logger_placeholder = True
39
  except ImportError:
40
- # ุฅุฐุง ูƒุงู†ุช ู…ูƒุชุจุฉ spaces ุบูŠุฑ ู…ูˆุฌูˆุฏุฉ (ู…ุซู„ ุงู„ุชุดุบูŠู„ ู…ุญู„ูŠุงู‹)ุŒ ุชุฌุงู‡ู„ ุงู„ุฃู…ุฑ
41
  pass
42
 
43
  import gradio as gr
@@ -795,6 +790,9 @@ def show_groups(update: Update, context: CallbackContext, page: int = 0, refresh
795
  rows.append([InlineKeyboardButton("๐Ÿ”„ ุชุญุฏูŠุซ", callback_data="grp_refresh")])
796
  rows.append([InlineKeyboardButton("๐Ÿ”™ ุฑุฌูˆุน", callback_data="menu_back")])
797
 
 
 
 
798
  q.edit_message_text(
799
  f"๐Ÿ“Œ <b>ุงุฎุชุฑ ุงู„ู…ุฌู…ูˆุนุงุช ู„ู„ุฅุฑุณุงู„</b>\n"
800
  f"ุฅุฌู…ุงู„ูŠ: {len(groups_list)} | ู…ุฎุชุงุฑ: {len(selected)}",
@@ -824,6 +822,7 @@ def groups_callback(update: Update, context: CallbackContext):
824
  db_save_user_groups(user_id, to_save)
825
  context.user_data.pop('groups_list', None)
826
  context.user_data.pop('temp_selected', None)
 
827
  q.answer(f"ุชู… ุญูุธ {len(to_save)} ู…ุฌู…ูˆุนุฉ โœ…", show_alert=True)
828
  show_main_menu(update, context)
829
  return
@@ -846,14 +845,10 @@ def groups_callback(update: Update, context: CallbackContext):
846
  else:
847
  selected.add(gid)
848
  context.user_data['temp_selected'] = selected
849
- page = 0
850
- try:
851
- import re as _re
852
- m = _re.search(r'(\d+)/(\d+)', q.message.text or "")
853
- if m:
854
- page = int(m.group(1)) - 1
855
- except Exception:
856
- pass
857
  q.answer()
858
  show_groups(update, context, page=page)
859
 
@@ -1113,7 +1108,6 @@ def run_bot_in_background():
1113
  updater.start_polling()
1114
  logger.info("โœ… Bot polling started.")
1115
 
1116
- # ุฅุจู‚ุงุก ุงู„ุฎูŠุท ุญูŠุงู‹ (Gradio ููŠ ุงู„ุฎูŠุท ุงู„ุฑุฆูŠุณูŠ)
1117
  while True:
1118
  threading.Event().wait(3600)
1119
 
@@ -1170,11 +1164,9 @@ def build_gradio_ui():
1170
 
1171
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Main โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1172
  if __name__ == "__main__":
1173
- # 1. ุดุบู‘ู„ ุงู„ุจูˆุช ููŠ ุฎูŠุท ู…ู†ูุตู„
1174
  bot_thread = threading.Thread(target=run_bot_in_background, daemon=True, name="bot-thread")
1175
  bot_thread.start()
1176
 
1177
- # 2. ุฃุทู„ู‚ ูˆุงุฌู‡ุฉ Gradio
1178
  logger.info("๐ŸŒ Starting Gradio interface on 0.0.0.0:7860")
1179
  demo = build_gradio_ui()
1180
  demo.queue().launch(
 
24
 
25
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
26
  # ๐Ÿ”ง ุญู„ ZeroGPU: ุฏุงู„ุฉ ูˆู‡ู…ูŠุฉ ู„ุฅุฑุถุงุก ู†ุธุงู… Hugging Face Spaces
 
 
27
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
28
  try:
29
  import spaces
 
32
  def _warmup_gpu():
33
  """ุฏุงู„ุฉ ูˆู‡ู…ูŠุฉ ูู‚ุท ู„ุฅุฑุถุงุก ู†ุธุงู… ZeroGPU. ู„ุง ุชุณุชุฎุฏู… GPU ูุนู„ูŠุงู‹."""
34
  return "ok"
 
 
35
  except ImportError:
 
36
  pass
37
 
38
  import gradio as gr
 
790
  rows.append([InlineKeyboardButton("๐Ÿ”„ ุชุญุฏูŠุซ", callback_data="grp_refresh")])
791
  rows.append([InlineKeyboardButton("๐Ÿ”™ ุฑุฌูˆุน", callback_data="menu_back")])
792
 
793
+ # โœจ ุญูุธ ุงู„ุตูุญุฉ ุงู„ุญุงู„ูŠุฉ ู„ู…ู†ุน ุงู„ุฑุฌูˆุน ู„ู„ุตูุญุฉ ุงู„ุฃูˆู„ู‰
794
+ context.user_data['groups_page'] = page
795
+
796
  q.edit_message_text(
797
  f"๐Ÿ“Œ <b>ุงุฎุชุฑ ุงู„ู…ุฌู…ูˆุนุงุช ู„ู„ุฅุฑุณุงู„</b>\n"
798
  f"ุฅุฌู…ุงู„ูŠ: {len(groups_list)} | ู…ุฎุชุงุฑ: {len(selected)}",
 
822
  db_save_user_groups(user_id, to_save)
823
  context.user_data.pop('groups_list', None)
824
  context.user_data.pop('temp_selected', None)
825
+ context.user_data.pop('groups_page', None)
826
  q.answer(f"ุชู… ุญูุธ {len(to_save)} ู…ุฌู…ูˆุนุฉ โœ…", show_alert=True)
827
  show_main_menu(update, context)
828
  return
 
845
  else:
846
  selected.add(gid)
847
  context.user_data['temp_selected'] = selected
848
+
849
+ # โœจ ุงู„ุญู„: ุงู‚ุฑุฃ ุงู„ุตูุญุฉ ุงู„ุญุงู„ูŠุฉ ู…ู† context ุจุฏู„ุงู‹ ู…ู† regex
850
+ page = context.user_data.get('groups_page', 0)
851
+
 
 
 
 
852
  q.answer()
853
  show_groups(update, context, page=page)
854
 
 
1108
  updater.start_polling()
1109
  logger.info("โœ… Bot polling started.")
1110
 
 
1111
  while True:
1112
  threading.Event().wait(3600)
1113
 
 
1164
 
1165
  # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Main โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1166
  if __name__ == "__main__":
 
1167
  bot_thread = threading.Thread(target=run_bot_in_background, daemon=True, name="bot-thread")
1168
  bot_thread.start()
1169
 
 
1170
  logger.info("๐ŸŒ Starting Gradio interface on 0.0.0.0:7860")
1171
  demo = build_gradio_ui()
1172
  demo.queue().launch(