noes14155 / Telegrambot-with-GPT

telegram bot with gpt
GNU General Public License v2.0
80 stars 31 forks source link

Image processing does't working #9

Closed vasmarfas closed 1 year ago

vasmarfas commented 1 year ago

I started the bot. Sent the random picture from my gallery Got this error in terminal: Error processing file https://api.telegram.org/file/(MY BOT TOKEN)/photos/file_5.jpg: (1, 'Error opening data file /usr/share/tesseract-ocr/4.00/tessdata/script/Devanagari.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'script/Devanagari\' Tesseract couldn\'t load any languages! Could not initialize tesseract.') 2023-06-20 17:20:24,208 (async_telebot.py:542 MainThread) ERROR - TeleBot: "Constructor parameter should be str"

I downloaded Devanagari.traineddata, put into /usr/share/tesseract-ocr/4.00/tessdata/ Changed main.py:31 to -> ocr = botocr.OCR(config=" --psm 3 --oem 3 -l Devanagari") Got this error in terminal: 2023-06-20 17:47:14,734 (async_telebot.py:542 MainThread) ERROR - TeleBot: "Constructor parameter should be str"

How to fix it?

noes14155 commented 1 year ago

Yes imaginepy API is down. I am looking for an alternative

noes14155 commented 1 year ago

Fixed

vasmarfas commented 1 year ago

If i send picture to bot, i get this error in terminal Error processing file https://api.telegram.org/file/bot5337896746:AAETEwCAfQPmj_T594ldwp1kxDkA27Xc7ew/photos/file_0.jpg: (1, 'Error opening data file /usr/share/tesseract-ocr/4.00/tessdata/script/Devanagari.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'script/Devanagari\' Tesseract couldn\'t load any languages! Could not initialize tesseract.') ERROR:asyncio:Task exception was never retrieved future: <Task finished name='Task-10' coro=<Dispatcher._process_polling_updates() done, defined at /usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py:407> exception=TypeError('Constructor parameter should be str')> Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 415, in _process_polling_updates for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)): File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 235, in process_updates return await asyncio.gather(tasks) File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/handler.py", line 117, in notify response = await handler_obj.handler(args, *partial_data) File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 256, in process_update return await self.message_handlers.notify(update.message) File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/handler.py", line 117, in notify response = await handler_obj.handler(args, **partial_data) File "/home/ubuntu/Telegrambot-with-GPT4free/main.py", line 277, in imageaudio_handler text = await bm.generate_imagecaption(image_url,HG_TOKEN) File "/home/ubuntu/Telegrambot-with-GPT4free/bot/botmedia.py", line 25, in generate_imagecaption async with session.get(url) as resp1, session.post(self.HG_img2text, headers=headers, data=await resp1.read()) as resp2: File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 1141, in aenter self._resp = await self._coro File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 423, in _request url = self._build_url(str_or_url) File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 357, in _build_url url = URL(str_or_url) File "/usr/local/lib/python3.10/dist-packages/yarl/_url.py", line 179, in new raise TypeError("Constructor parameter should be str") TypeError: Constructor parameter should be str

noes14155 commented 1 year ago

Fixed. pronlem from wrong variable name

vasmarfas commented 1 year ago

Error again

ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-11' coro=<Dispatcher._process_polling_updates() done, defined at /usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py:407> exception=TypeError('Constructor parameter should be str')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 415, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
  File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/dispatcher.py", line 256, in process_update
    return await self.message_handlers.notify(update.message)
  File "/usr/local/lib/python3.10/dist-packages/aiogram/dispatcher/handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "/home/ubuntu/Telegrambot-with-GPT4free/main.py", line 255, in imageaudio_handler
    text = await bm.generate_imagecaption(image_url,HG_TOKEN)
  File "/home/ubuntu/Telegrambot-with-GPT4free/bot/botmedia.py", line 26, in generate_imagecaption
    async with session.post(self.HG_img2text, headers=headers, data=await resp1.read()) as resp2:
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 423, in _request
    url = self._build_url(str_or_url)
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 357, in _build_url
    url = URL(str_or_url)
  File "/usr/local/lib/python3.10/dist-packages/yarl/_url.py", line 179, in __new__
    raise TypeError("Constructor parameter should be str")
TypeError: Constructor parameter should be str
noes14155 commented 1 year ago

Use with the new code or change your env file hgimg2text to HGIMG2TEXT its already changed in the example file