performance improvements
Browse files- App/Transcription/Utils/fastapi_tasks.py +5 -5
- App/__init__.py +10 -1
- App/app.py +3 -1
- app.py +4 -3
App/Transcription/Utils/fastapi_tasks.py
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
from App import
|
2 |
from fastapi import UploadFile
|
3 |
from App.Transcription.Model import Transcriptions
|
4 |
|
5 |
|
6 |
async def perform_background_task(file: UploadFile, task_id: str):
|
7 |
-
data = await
|
8 |
-
|
9 |
-
|
10 |
caption=file.filename,
|
11 |
-
file=f"./{file.filename}",
|
12 |
)
|
|
|
13 |
# get entry and update
|
14 |
entry: Transcriptions = await Transcriptions.objects.filter(task_id=task_id).first()
|
15 |
await entry.update(tl_file_id=str(data.id))
|
|
|
1 |
+
from App import upload_bot
|
2 |
from fastapi import UploadFile
|
3 |
from App.Transcription.Model import Transcriptions
|
4 |
|
5 |
|
6 |
async def perform_background_task(file: UploadFile, task_id: str):
|
7 |
+
data = await upload_bot.send_document(
|
8 |
+
document=f"./{file.filename}",
|
9 |
+
chat_id=-1001925049183,
|
10 |
caption=file.filename,
|
|
|
11 |
)
|
12 |
+
|
13 |
# get entry and update
|
14 |
entry: Transcriptions = await Transcriptions.objects.filter(task_id=task_id).first()
|
15 |
await entry.update(tl_file_id=str(data.id))
|
App/__init__.py
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
import uuid, contextvars
|
2 |
from telethon import TelegramClient
|
3 |
-
|
4 |
|
5 |
bot = TelegramClient(
|
6 |
"transcription_bot",
|
7 |
api_id=870972,
|
8 |
api_hash="ce2efaca02dfcd110941be6025e9ac0d",
|
9 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import uuid, contextvars
|
2 |
from telethon import TelegramClient
|
3 |
+
from pyrogram import Client
|
4 |
|
5 |
bot = TelegramClient(
|
6 |
"transcription_bot",
|
7 |
api_id=870972,
|
8 |
api_hash="ce2efaca02dfcd110941be6025e9ac0d",
|
9 |
)
|
10 |
+
|
11 |
+
|
12 |
+
upload_bot = Client(
|
13 |
+
str("the book"),
|
14 |
+
api_id=870972,
|
15 |
+
api_hash="ce2efaca02dfcd110941be6025e9ac0d",
|
16 |
+
bot_token="6183919505:AAEhHFt4mI18bQeAf2Lj7AePXFRPVLrOFM8",
|
17 |
+
workers=9,
|
18 |
+
)
|
App/app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
-
from App import bot
|
3 |
from .Users.UserRoutes import user_router
|
4 |
from .modelInit import models, database
|
5 |
from .Transcription.TranscriptionRoutes import transcription_router
|
@@ -30,6 +30,7 @@ app.add_middleware(
|
|
30 |
@app.on_event("startup")
|
31 |
async def startup_event():
|
32 |
await bot.start()
|
|
|
33 |
await models.create_all()
|
34 |
if not database.is_connected:
|
35 |
await database.connect()
|
@@ -39,6 +40,7 @@ async def startup_event():
|
|
39 |
@app.on_event("shutdown")
|
40 |
async def shutdown_event():
|
41 |
await bot.stop()
|
|
|
42 |
if not database.is_connected:
|
43 |
await database.disconnect()
|
44 |
print("shutting down!")
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from App import bot, upload_bot
|
3 |
from .Users.UserRoutes import user_router
|
4 |
from .modelInit import models, database
|
5 |
from .Transcription.TranscriptionRoutes import transcription_router
|
|
|
30 |
@app.on_event("startup")
|
31 |
async def startup_event():
|
32 |
await bot.start()
|
33 |
+
await upload_bot.start()
|
34 |
await models.create_all()
|
35 |
if not database.is_connected:
|
36 |
await database.connect()
|
|
|
40 |
@app.on_event("shutdown")
|
41 |
async def shutdown_event():
|
42 |
await bot.stop()
|
43 |
+
await upload_bot.stop()
|
44 |
if not database.is_connected:
|
45 |
await database.disconnect()
|
46 |
print("shutting down!")
|
app.py
CHANGED
@@ -4,10 +4,11 @@ import logging
|
|
4 |
# Configure logging
|
5 |
logging.basicConfig(
|
6 |
level=logging.DEBUG,
|
7 |
-
format=
|
8 |
-
datefmt=
|
9 |
)
|
10 |
|
|
|
11 |
def run_command(command):
|
12 |
try:
|
13 |
output = subprocess.check_output(
|
@@ -19,5 +20,5 @@ def run_command(command):
|
|
19 |
|
20 |
|
21 |
# Example usage
|
22 |
-
command = "uvicorn App.app:app --host 0.0.0.0 --port 7860 & celery -A App.Worker.celery worker --loglevel=info"
|
23 |
run_command(command)
|
|
|
4 |
# Configure logging
|
5 |
logging.basicConfig(
|
6 |
level=logging.DEBUG,
|
7 |
+
format="%(asctime)s - %(levelname)s - %(message)s",
|
8 |
+
datefmt="%Y-%m-%d %H:%M:%S",
|
9 |
)
|
10 |
|
11 |
+
|
12 |
def run_command(command):
|
13 |
try:
|
14 |
output = subprocess.check_output(
|
|
|
20 |
|
21 |
|
22 |
# Example usage
|
23 |
+
command = "uvicorn App.app:app --host 0.0.0.0 --port 7860 --workers 2 & celery -A App.Worker.celery worker --loglevel=info"
|
24 |
run_command(command)
|