Kanhshsh commited on
Commit
7d376c9
Β·
verified Β·
1 Parent(s): eece125

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -39,8 +39,11 @@ async def bash_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
39
  except Exception as e:
40
  output = f"Error running command: {e}"
41
 
42
- await update.message.reply_text(f"$ {cmd}\n{output}")
43
- telegram_cmd_logs.append(f"$ {cmd}\n{output}")
 
 
 
44
  if len(telegram_cmd_logs) > 50:
45
  telegram_cmd_logs.pop(0)
46
 
@@ -57,7 +60,7 @@ def start_bot():
57
  bot_app.add_handler(CommandHandler("bash", bash_command))
58
  bot_running = True
59
  log_queue.put("[Bot] Bot started.")
60
- await bot_app.run_polling()
61
 
62
  loop = asyncio.new_event_loop()
63
 
@@ -131,7 +134,8 @@ with gr.Blocks() as demo:
131
 
132
  log_output = gr.Textbox(value="", label="πŸ“œ Bot & Telegram Logs", lines=15, interactive=False)
133
 
134
- cmd_input.submit(run_terminal, inputs=cmd_input, outputs=terminal_output)
 
135
 
136
  def start_click():
137
  start_bot()
@@ -144,7 +148,7 @@ with gr.Blocks() as demo:
144
  start_btn.click(start_click, outputs=log_output)
145
  stop_btn.click(stop_click, outputs=log_output)
146
 
147
- # Auto-updating logs without `every` (Gradio v5 way)
148
  def background_log_updater():
149
  while True:
150
  time.sleep(3)
 
39
  except Exception as e:
40
  output = f"Error running command: {e}"
41
 
42
+ result = f"$ {cmd}\n{output}"
43
+ await update.message.reply_text(result)
44
+
45
+ log_queue.put(result)
46
+ telegram_cmd_logs.append(result)
47
  if len(telegram_cmd_logs) > 50:
48
  telegram_cmd_logs.pop(0)
49
 
 
60
  bot_app.add_handler(CommandHandler("bash", bash_command))
61
  bot_running = True
62
  log_queue.put("[Bot] Bot started.")
63
+ await bot_app.run_polling(stop_signals=None)
64
 
65
  loop = asyncio.new_event_loop()
66
 
 
134
 
135
  log_output = gr.Textbox(value="", label="πŸ“œ Bot & Telegram Logs", lines=15, interactive=False)
136
 
137
+ # Use stream for generator-based live output
138
+ cmd_input.stream(run_terminal, inputs=cmd_input, outputs=terminal_output)
139
 
140
  def start_click():
141
  start_bot()
 
148
  start_btn.click(start_click, outputs=log_output)
149
  stop_btn.click(stop_click, outputs=log_output)
150
 
151
+ # Auto-updating logs using Gradio v5-style load
152
  def background_log_updater():
153
  while True:
154
  time.sleep(3)