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!')