-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (45 loc) · 1.9 KB
/
main.py
File metadata and controls
56 lines (45 loc) · 1.9 KB
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
52
53
54
55
56
from aiogram import Bot, Dispatcher, types, executor
import random
import os
from dotenv import load_dotenv
import joblib
import pandas as pd
load_dotenv()
bot_token = os.getenv('token')
bot = Bot(token=bot_token)
dp = Dispatcher(bot)
model = joblib.load("model/best_tpot_model1.joblib")
# Define the /start command handler
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
# Send a welcome message to the user
await message.reply(
"Welcome to the Tennis Match Predictor Bot! To predict the winner of a match, use this bot.\n"
"You have to send a csv file with such columns\n"
"Here is the example\n"
)
with open('good.csv', 'rb') as csv_file:
await message.reply_document(csv_file)
@dp.message_handler(content_types=types.ContentTypes.DOCUMENT)
async def handle_csv_file(message: types.Message):
# Check if the message contains a document
if message.document.mime_type == 'text/csv':
# Download the document
file_id = message.document.file_id
file_path = await bot.get_file(file_id)
file_data = await bot.download_file(file_path.file_path)
# Process the CSV file
df = pd.read_csv(file_data)
df = df[[col for col in df.columns if col != 'Unnamed: 0']]
# Do something with the dataframe, such as extracting information or performing analysis
# Reply with a message
reply_message = f"CSV file received and processed! Rows: {len(df)}, Columns: {len(df.columns)}"
# await bot.send_message(chat_id=message.chat.id, text=text)
res = model.predict(df.convert_dtypes())
pd.DataFrame(res).to_csv('result.csv')
with open('result.csv', 'rb') as csv_file:
await message.reply_document(csv_file)
else:
await message.reply("Please upload a CSV file.")
# Create the bot and start the event loop
executor.start_polling(dp)