Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show images from Bard's reply #102

Merged
merged 11 commits into from
Dec 9, 2023
Merged

Conversation

Hanssen0
Copy link
Contributor

@Hanssen0 Hanssen0 commented Dec 9, 2023

No description provided.

@Hanssen0 Hanssen0 force-pushed the bard-images branch 2 times, most recently from bb38211 to 27998fa Compare December 9, 2023 12:00
* Allow text with photos, see
  `RequestResponseContainer.response_images`
* All captions are formatted in Markdown
* Use `md2tgmd` to escape markdown content, keep the original format
@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

Everything works for me regarding the generation of images by the Bard (except for the need to fix md2tgmd)

Fix formatting
@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

Bing Image Generator stopped working for me

Traceback (most recent call last):
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 197, in send_message_async
    await _send_text_async_split(config, messages[lang], request_response, end)
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 280, in _send_text_async_split
    = request_response.response[response_part_index_start:response_part_index_stop].strip()
AttributeError: 'list' object has no attribute 'strip'

Error is here

response_part \
            = request_response.response[response_part_index_start:response_part_index_stop].strip()

@Hanssen0
Copy link
Contributor Author

Hanssen0 commented Dec 9, 2023

Bing Image Generator stopped working for me

I tried to fix it. I can't use Bing on my server, so I didn't test this. I'm sorry.

@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

馃檭馃檭馃檭

Traceback (most recent call last):
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 198, in send_message_async
    await _send_text_async_split(config, messages[lang], request_response, end)
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 269, in _send_text_async_split
    (await asyncio.gather(*[parse_img(img)
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 236, in parse_img
    img = Image.open(io.BytesIO(res.content))
  File "/home/fern/GPT-Telegramus/venv/lib/python3.10/site-packages/PIL/Image.py", line 3305, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f1b0e0d53f0>

@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

Pls wait, I'll trying to fix it now

@Hanssen0
Copy link
Contributor Author

Hanssen0 commented Dec 9, 2023

馃檭馃檭馃檭

Traceback (most recent call last):
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 198, in send_message_async
    await _send_text_async_split(config, messages[lang], request_response, end)
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 269, in _send_text_async_split
    (await asyncio.gather(*[parse_img(img)
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 236, in parse_img
    img = Image.open(io.BytesIO(res.content))
  File "/home/fern/GPT-Telegramus/venv/lib/python3.10/site-packages/PIL/Image.py", line 3305, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f1b0e0d53f0>

I need the image links from Bing to identify this problem.

@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

馃檭馃檭馃檭

Traceback (most recent call last):
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 198, in send_message_async
    await _send_text_async_split(config, messages[lang], request_response, end)
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 269, in _send_text_async_split
    (await asyncio.gather(*[parse_img(img)
  File "/home/fern/GPT-Telegramus/BotHandler.py", line 236, in parse_img
    img = Image.open(io.BytesIO(res.content))
  File "/home/fern/GPT-Telegramus/venv/lib/python3.10/site-packages/PIL/Image.py", line 3305, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f1b0e0d53f0>

I need the image links from Bing to identify this problem.

Saving images locally is also not good. Telegram can accept links as input. The only thing we need to do is avoid the .svg file. Also, we need to fix the data saver (there is no check that response is image). So, please wait, I鈥檒l trying to fix this now

@Hanssen0
Copy link
Contributor Author

Hanssen0 commented Dec 9, 2023

Saving images locally is also not good. Telegram can accept links as input. The only thing we need to do is avoid the .svg file. Also, we need to fix the data saver (there is no check that response is image). So, please wait, I鈥檒l trying to fix this now

The problem I'm facing is that some links returned from Bard are not valid images or supported image formats. Maybe we can use requests.head to check the MEME type of link. But still, if the image URL is not valid, telegram will reject the whole message.

@Hanssen0
Copy link
Contributor Author

Hanssen0 commented Dec 9, 2023

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f1b0e0d53f0>

Fixed. Tested on my local machine.

@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

Now i'm getting responses from Bard like this 馃檭

Me:
Hi! Please draw a Cat

Bard:
Sure, here is the graph:
[image-tag: code_execution_image_1_1702148263.9369574.png]

@Hanssen0
Copy link
Contributor Author

Hanssen0 commented Dec 9, 2023

Bard: Sure, here is the graph: [image-tag: code_execution_image_1_1702148263.9369574.png]

It seems like the image source from Bard blocked access from a bot. I'm trying to add User-Agent for requests, which seems to work.

I'm fixing the problem, which image might be too big. I will push my code later.

@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

I've updated a few things including image logging. Tested on Bard and BingImageGen

@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

Bard: Sure, here is the graph: [image-tag: code_execution_image_1_1702148263.9369574.png]

It seems like the image source from Bard blocked access from a bot. I'm trying to add User-Agent for requests, which seems to work.

I'm fixing the problem, which image might be too big. I will push my code later.

Ok I'll wait until u fix image-tag response from Bard

Copy link
Owner

@F33RNI F33RNI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent solution for checking image format 馃憤

@Hanssen0
Copy link
Contributor Author

Hanssen0 commented Dec 9, 2023

Hi! Please draw a Cat

I tested your prompt and got the same answer. The Bard API didn't send us any images.

image

This is the result from the Bard website. I don't think we can support this now.

@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

Maybe these graphs have base url to retrieve these type of images code_execution_image_1_1702148263.9369574.png ?

@Hanssen0
Copy link
Contributor Author

Hanssen0 commented Dec 9, 2023

{
  "content": "Sure, here is the graph:\n[image-tag: code_execution_image_1_1702151707.76185.png]",
  "conversation_id": "c_b1ce829e646419c2",
  "response_id": "r_36009817021c94c2",
  "factuality_queries": null,
  "text_query": "",
  "choices": [
    {
      "id": "rc_1bee96994a572ecc",
      "content": [
        "Sure, here is the graph:\n[image-tag: code_execution_image_1_1702151707.76185.png]"
      ]
    }
  ],
  "links": [
    "https://lh3.googleusercontent.com/bard/AL4VpuO_LqC_HH8q4ODUXBxrX3LVGQZ846eEEBKA7nDEMS8fFSvL6MBUmg87qeSq4X54UsmAHGgTzKQVFsJIXGSUrIebaWPgOZenNvxZNwG_tLTM-15zylBp3FD0xt4-Zvl6rqkpBRdcRNZ9rdY8PWBa3IrXDJAJ2z3Cy5jmDSSeQX9pHM7me3xH1e7nVvPLfJdYGzXQZ5kwAi2W1us0lDfonIe9cAq-cdcOTkDEkWDQimMGARl2HBCdk-bBIg9aQe68KokSjAviTJs3Nl3HR1yxgf2FMtSL1JI6J5FZoW97KFVVIv_TRrRg1pCxOYVUuQT6cvyPNeI1EvxVRNaA-Ls"
  ],
  "images": [],
  "program_lang": null,
  "code": null,
  "status_code": 200
}

Here is the response from Bard. As you can see, the image URL is in the links list. The content is unrelated to the image-tag. Maybe we can use links instead of images?

@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

Can we retrieve images from them?
Screenshot_20231209_150730_Chrome.jpg

@Hanssen0
Copy link
Contributor Author

Hanssen0 commented Dec 9, 2023

Can we retrieve images from them?

I can do that from my browser. It seems it needs my cookies to access the URL.
I suggest that we should just ignore this situation. These images is not that useful...

@F33RNI
Copy link
Owner

F33RNI commented Dec 9, 2023

OK
Then can I merge now?

@Hanssen0
Copy link
Contributor Author

Hanssen0 commented Dec 9, 2023

OK Then can I merge now?

Yes

@F33RNI F33RNI merged commit fe97feb into F33RNI:master Dec 9, 2023
2 checks passed
@Hanssen0 Hanssen0 deleted the bard-images branch December 16, 2023 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants