RXTIME commited on
Commit
614e255
·
verified ·
1 Parent(s): c34f783

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +61 -11
README.md CHANGED
@@ -1,14 +1,64 @@
1
  ---
2
- title: Conversordevideo
3
- emoji: 📊
4
- colorFrom: green
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.14.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- short_description: Traduza automaticamente vídeos para português
12
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ import os
3
+ import telegram
4
+ from telegram.ext import Application, CommandHandler
5
+ from flask import Flask
6
+ from threading import Thread
7
+ import schedule
8
+ import time
9
+
10
+ # Inicializa o Flask
11
+ app = Flask(__name__)
12
+
13
+ # Rota básica para manter o Space ativo
14
+ @app.route('/')
15
+ def home():
16
+ return "Hypercycle Bot is running!"
17
+
18
+ # Função para rodar o Flask em uma thread separada
19
+ def run_flask():
20
+ app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))
21
+
22
+ # Função de exemplo para o comando /start
23
+ async def start(update, context):
24
+ await update.message.reply_text('Hello! I am Hypercycle Bot.')
25
+
26
+ # Função para tarefas agendadas
27
+ def scheduled_task():
28
+ print("Running scheduled task...") # Substitua por sua lógica
29
+
30
+ # Função principal do bot
31
+ def main():
32
+ # Obtém o token do Telegram das variáveis de ambiente
33
+ TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN')
34
+ if not TELEGRAM_TOKEN:
35
+ raise ValueError("TELEGRAM_TOKEN not set in environment variables")
36
+
37
+ # Configura o bot
38
+ application = Application.builder().token(TELEGRAM_TOKEN).build()
39
+
40
+ # Adiciona handlers de comandos
41
+ application.add_handler(CommandHandler("start", start))
42
+
43
+ # Inicia o bot
44
+ print("Bot is starting...")
45
+ application.run_polling()
46
+
47
+ # Função para rodar o agendador em uma thread separada
48
+ def run_scheduler():
49
+ schedule.every(10).seconds.do(scheduled_task) # Exemplo: tarefa a cada 10s
50
+ while True:
51
+ schedule.run_pending()
52
+ time.sleep(1)
53
+
54
+ if __name__ == '__main__':
55
+ # Inicia o Flask em uma thread
56
+ Thread(target=run_flask).start()
57
+
58
+ # Inicia o agendador em uma thread
59
+ Thread(target=run_scheduler).start()
60
+
61
+ # Inicia o bot
62
+ main()
63
 
64
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference