File size: 1,610 Bytes
991daab c7e76b4 2d2b8f7 991daab b1e8c8d 991daab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import streamlit as st
import threading
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging
import yfinance as yf
import xgboost as xgb
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
import telebot
# Set up logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
TOKEN = '6528763221:AAFggIwglirRBY95Nz0OPV2KEU_CbllESnI' # Replace 'YOUR_TOKEN' with the token given to you by BotFather
def start_bot():
"""Start the bot."""
# Telegram bot code here
def start(update, context):
update.message.reply_text('Hi there! Send me any message and I’ll reply "Hey you".')
def echo(update, context):
update.message.reply_text('Hey you')
def error(update, context):
logger.warning('Update "%s" caused error "%s"', update, context.error)
updater = Updater(TOKEN, use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(MessageHandler(Filters.text & ~Filters.command, echo))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
# Streamlit app
st.title('Telegram Bot Controller')
# Define a function to run the bot in a separate thread to avoid blocking
def run_bot_thread():
bot_thread = threading.Thread(target=start_bot)
bot_thread.start()
if st.button('Start Bot'):
st.write('Bot is starting...')
run_bot_thread() # start the bot in a separate thread
st.write('Bot has started!') |