Bard-API
Bard-API copied to clipboard
Provide Links For Images Generated by Google's Bard AI
Hello,
It seems BardAI now supports image generation as per below snapshot. However the Bard-API only returns the alt-image-text for the generated image. Is there a way to include the links of the generated images?
Thank you for bringing up this interesting issue. While there is a high possibility that it may not work, I will investigate it further.
Would really like it to have the links of generated images, maybe put a network interceptor to catch hold of these links - based on domain/sub-domain name maybe?
Edit : Found some libs like - mitmproxy (Man-in-the-Middle Proxy) that helps to intercept additional requests that the leading API req makes So prob catch hold of t0.gstatic.com/images URI and acc append the response to the BARD API
Bard is a language model, not an image generation AI model. However, I have recently confirmed the addition of the image web search feature to Google Bard. As a temporary solution, it returns the links included in the response. Please note that this feature is temporary and is only deployed in the developer version. Please use it as follows.
pip install git+https://github.com/dsdanielpark/Bard-API.git
from bardapi import Bard
bard = Bard(token='xxxxxxxxxxx')
res = bard.get_answer("Find me an image of the main entrance of Stanford University.")
res['links']
Yes, from the images response list - it looks the the uri for generated image is : t0.gstatic.com/images which could be appended in the response string.
Any timelines around which this feature is deployed to prod?
It is not desirable to continuously add specific functionalities to the developer deployment version. Therefore, we recommend post-processing and using the following approach instead.
token='xxxxxxxx'
bard = Bard(token=token)
link_list = bard.get_answer("Find me an image of the main entrance of Stanford University.")['links']
filtered_links = [link for link in link_list if "https://lh3.googleusercontent.com/" in link or "http://t0.gstatic.com/" in link]
print(filtered_links)
Thanks for your detailed response, just have one final query : Any timelines around which this feature is deployed to prod?
Please check this commit hash acbf3fba8453ea354a0b53e59230175a44500171
I just added support in my repo https://github.com/acheong08/Bard/compare/1.0.3...1.1.0
You can parse for images
if len(json_chat_data) >= 3:
for img in json_chat_data[4][0][4]:
images.add(img[0][0][0])
images = set()
if len(json_chat_data) >= 3:
if len(json_chat_data[4][0]) >= 3:
for img in json_chat_data[4][0][4]:
images.add(img[0][0][0])
Could you kindly contribute by including this part and the part where "images" is the key?
chat_data = json.loads(resp.content.splitlines()[3])[0][2]
if not chat_data:
return {"content": f"Google Bard encountered an error: {resp.content}."}
json_chat_data = json.loads(chat_data)
images = set()
if len(json_chat_data) >= 3:
if len(json_chat_data[4][0]) >= 4:
for img in json_chat_data[4][0][4]:
images.add(img[0][0][0])
results = {
"content": json_chat_data[0][0],
"conversation_id": json_chat_data[1][0],
"response_id": json_chat_data[1][1],
"factualityQueries": json_chat_data[3],
"textQuery": json_chat_data[2][0] if json_chat_data[2] is not None else "",
"choices": [{"id": i[0], "content": i[1]} for i in json_chat_data[4]],
"images": images,
}
Please check this commit hash
acbf3fba8453ea354a0b53e59230175a44500171
Was looking to have this feature in the official pip package - 'bardapi'
Use developer version or you can install via github tag. Refere this CoCoder package. https://github.com/dsdanielpark/Co-Coder/blob/main/requirements.txt
@dsdanielpark based on your code, I have converted it to PHP and support getting images Bard AI PHP version
![]()
Bard is a language model, not an image generation AI model. However, I have recently confirmed the addition of the image web search feature to Google Bard. As a temporary solution, it returns the links included in the response. Please note that this feature is temporary and is only deployed in the developer version. Please use it as follows.
pip install git+https://github.com/dsdanielpark/Bard-API.git
from bardapi import Bard bard = Bard(token='xxxxxxxxxxx') res = bard.get_answer("Find me an image of the main entrance of Stanford University.") res['links']
Hi Daniel, this works in Google colab and gives the links, but doesn't work on Jupyter notebook; why so?
There could be various reasons for the issue. If it continues to not work on your local Jupyter Notebook, please feel free to create a new issue. Thank you.