1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] the asynchronous Python program is blocked

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 17:42.

  1. Stack

    Stack Membro Participativo

    i decided to write a telegram bot on aiogram with the implementation of the qwen 2.5 math neural network via the gradioc_lient api.

    The problem is that when there is an Api request, the asynchronous program is blocked and the bot stops responding until it produces a result.

    Is there any way to fix this?

    import uuid
    from aiogram import Router, F
    from aiogram.filters import CommandStart, Command
    from aiogram.types import Message
    from gradio_client import Client, handle_file



    start_router = Router()


    async def image_hueta(fileName):
    client = Client("Qwen/Qwen2-Math-Demo")
    result = client.predict(
    image=handle_file(fileName),
    sketchpad={"background": handle_file(
    'https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'), "layers": [],
    "composite": None},
    question="доказать равенсво",
    api_name="/math_chat_bot"
    )
    return result

    @start_router.message(CommandStart())
    async def cmd_start(message: Message):
    await message.answer("Хай!!!")

    @start_router.message(F.photo)
    async def send_photo(message: Message):
    local_filename = f"{uuid.uuid4()}.png"
    await message.bot.download(file = message.photo[-1].file_id, destination=local_filename)
    await message.answer("Ваш запрос обрабатывается...")
    result = await image_hueta(local_filename)
    await message.answer(f"{result}")



    .

    Continue reading...

Compartilhe esta Página