Kanhshsh commited on
Commit
eceb86e
Β·
verified Β·
1 Parent(s): b766703

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -2,18 +2,39 @@ import gradio as gr
2
  import subprocess
3
  import threading
4
 
5
- # Run the bot in background
 
6
  def run_bot():
7
- subprocess.Popen(["python3", "bot/main.py"])
 
 
 
 
 
 
 
 
 
8
 
 
9
  threading.Thread(target=run_bot, daemon=True).start()
10
 
11
  def launch_bot():
12
- return "The Movie Provider Bot is running in the background. Interact via Telegram."
 
 
 
13
 
14
  with gr.Blocks() as demo:
15
  gr.Markdown("# 🎬 TheMovieProviderBot Interface")
16
  gr.Markdown("Interact with the bot on Telegram.")
17
- gr.Button("Start Bot").click(launch_bot)
 
 
 
 
 
 
 
18
 
19
- demo.launch()
 
2
  import subprocess
3
  import threading
4
 
5
+ logs = ""
6
+
7
  def run_bot():
8
+ global logs
9
+ process = subprocess.Popen(
10
+ ["python3", "bot.py"],
11
+ stdout=subprocess.PIPE,
12
+ stderr=subprocess.STDOUT,
13
+ text=True,
14
+ bufsize=1
15
+ )
16
+ for line in process.stdout:
17
+ logs += line
18
 
19
+ # Start the bot in a background thread
20
  threading.Thread(target=run_bot, daemon=True).start()
21
 
22
  def launch_bot():
23
+ return "βœ… Bot launched successfully."
24
+
25
+ def get_logs():
26
+ return logs[-2000:] # Show last 2000 characters
27
 
28
  with gr.Blocks() as demo:
29
  gr.Markdown("# 🎬 TheMovieProviderBot Interface")
30
  gr.Markdown("Interact with the bot on Telegram.")
31
+ gr.Markdown("[πŸ“¦ Click here to download bot files](static/setup.zip)")
32
+
33
+ with gr.Row():
34
+ gr.Button("Start Bot").click(launch_bot)
35
+ gr.Button("πŸ” Refresh Logs")
36
+
37
+ log_output = gr.Textbox(label="πŸ“„ Bot Logs", lines=20)
38
+ demo.load(get_logs, None, log_output, every=3)
39
 
40
+ demo.launch()