omar1232 commited on
Commit
e6d2e47
·
verified ·
1 Parent(s): 3ff5eb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -1,29 +1,25 @@
1
  import threading
2
- import asyncio
3
  import gradio as gr
4
  from telegram import Update
5
  from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
6
 
7
  # ====== Telegram Bot Setup ======
 
8
 
9
- TELEGRAM_TOKEN = "8030235633:AAHKvxM9Nzp0DkxfdotMux3572tC_5CGEUA" # Replace this with your real bot token
10
-
11
- # Define a simple Telegram command handler
12
  async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
13
  await update.message.reply_text("Hello! I'm your bot!")
14
 
15
  # ====== Gradio App Setup ======
16
 
17
- # Define a simple Gradio function
18
  def greet(name):
19
  return f"Hello, {name}!"
20
 
21
- # Create the Gradio interface
22
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
23
 
24
- # Function to run Gradio in a separate thread
25
  def run_gradio():
26
- demo.launch(share=True) # 'share=True' creates a public link
27
 
28
  # ====== Start Both Gradio & Telegram Bot ======
29
 
@@ -32,7 +28,7 @@ if __name__ == "__main__":
32
  gradio_thread = threading.Thread(target=run_gradio)
33
  gradio_thread.start()
34
 
35
- # Start the Telegram bot in the main thread (avoids signal issues)
36
  application = ApplicationBuilder().token(TELEGRAM_TOKEN).build()
37
  application.add_handler(CommandHandler("start", start))
38
  application.run_polling()
 
1
  import threading
 
2
  import gradio as gr
3
  from telegram import Update
4
  from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
5
 
6
  # ====== Telegram Bot Setup ======
7
+ TELEGRAM_TOKEN = "PUT_YOUR_VALID_TELEGRAM_BOT_TOKEN_HERE" # Replace this with your real bot token
8
 
9
+ # Simple Telegram command handler
 
 
10
  async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
11
  await update.message.reply_text("Hello! I'm your bot!")
12
 
13
  # ====== Gradio App Setup ======
14
 
 
15
  def greet(name):
16
  return f"Hello, {name}!"
17
 
 
18
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
19
 
20
+ # Function to run Gradio (no SSR or share=True needed on Hugging Face Spaces)
21
  def run_gradio():
22
+ demo.launch(ssr=False) # SSR disabled, share not needed on Spaces
23
 
24
  # ====== Start Both Gradio & Telegram Bot ======
25
 
 
28
  gradio_thread = threading.Thread(target=run_gradio)
29
  gradio_thread.start()
30
 
31
+ # Start the Telegram bot in the main thread
32
  application = ApplicationBuilder().token(TELEGRAM_TOKEN).build()
33
  application.add_handler(CommandHandler("start", start))
34
  application.run_polling()