HanaokaYuzu / Gemini-API

✨ Elegant async Python API for Google Gemini web app
https://pypi.org/project/gemini-webapi/
GNU Affero General Public License v3.0
157 stars 20 forks source link

generate images not working #34

Closed a-sajjad72 closed 1 week ago

a-sajjad72 commented 1 month ago

I was testing Gemini. Everything works seems to be fine rest of the image generation. I don't know why it is happening. I tried these prompts which works fine

When I try a prompt with "generate image" it shows an error.

Traceback

Traceback (most recent call last):
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 390, in generate_content
    and [
        ^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 392, in <listcomp>
    url=image[0][3][3],
        ~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 55, in wrapper
    return await func(client, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 420, in generate_content
    raise APIError(
gemini_webapi.exceptions.APIError: Failed to parse response body. Data structure is invalid.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 390, in generate_content
    and [
        ^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 392, in <listcomp>
    url=image[0][3][3],
        ~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 55, in wrapper
    return await func(client, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 420, in generate_content
    raise APIError(
gemini_webapi.exceptions.APIError: Failed to parse response body. Data structure is invalid.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 390, in generate_content
    and [
        ^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 392, in <listcomp>
    url=image[0][3][3],
        ~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\testing.py", line 26, in <module>
    asyncio.run(main())
  File "C:\Users\asajj\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\testing.py", line 20, in main
    response = await client.generate_content("Generate some pictures of cats")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 59, in wrapper
    return await wrapper(client, *args, retry=retry - 1, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 59, in wrapper
    return await wrapper(client, *args, retry=retry - 1, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 55, in wrapper
    return await func(client, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asajj\OneDrive\Desktop\Sarmad_Tasks\venv\Lib\site-packages\gemini_webapi\client.py", line 420, in generate_content
    raise APIError(
gemini_webapi.exceptions.APIError: Failed to parse response body. Data structure is invalid.
HanaokaYuzu commented 2 weeks ago

Debugging this could be tricky. According to user report, different accounts may have different response structure when generating image. If you know how to debug python code, please set a breakpoint at line 386, check the structure of candidate and find out where those generated images are located. Without this info i can do nothing on my side.

https://github.com/HanaokaYuzu/Gemini-API/blob/03387314a25b4307b01cd44909e9fc1f97d33824/src/gemini_webapi/client.py#L386-L403

a-sajjad72 commented 2 weeks ago

Debugging this could be tricky. According to user report, different accounts may have different response structure when generating image. If you know how to debug python code, please set a breakpoint at line 386, check the structure of candidate and find out where those generated images are located. Without this info i can do nothing on my side.

https://github.com/HanaokaYuzu/Gemini-API/blob/03387314a25b4307b01cd44909e9fc1f97d33824/src/gemini_webapi/client.py#L386-L403

sure i'll do that and update you in a while.

HanaokaYuzu commented 2 weeks ago

Thanks, and pr is also welcomed :)

a-sajjad72 commented 1 week ago

so this is the value of candidate. all the values are null.

['rc_5fb47a5dae51748c', ['Creating your image with Imagen 3...\n\n[Imagen of a fake image]'], [], None, None, None, None, None, [1], 'en', None, None, [None, None, None, None, None, None, [...], [...]], None, None, None, None, None, None, None, None, [False], None, False]

but when I tried to check the response.text for the request, it contains some links. here is the sample

')]}\'\n\n[["wrb.fr",null,"[null,[\\"c_906b773f4a219e58\\",\\"r_5f7601c914ddb8f0\\"],null,null,[[\\"rc_5fb47a5dae51748c\\",[\\"Creating your image with Imagen 3...\\\\n\\\\n[Imagen of a fake image]\\"],[],null,null,null,null,null,[1],\\"en\\",null,null,[null,null,null,null,null,null,[3],[[[null,[\\"[Imagen of a fake image]\\",null,null,null,null,2,null,null,true],null,[],null,true]],null,[false,true]]],null,null,null,null,null,null,null,null,[false],null,false]],[\\"Jalalpur Jattan, Pakistan\\",\\"SWML_DESCRIPTION_FROM_YOUR_INTERNET_ADDRESS\\",false,[[[null,null,null,[[300,200],null,null,[[326284118,741504246],[326454442,741706506]]]]],[[2,null,null,null,null,[null,null,null,[[[326369280,741605376],1068.5302,1931574222,1,864863983]]]]],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[null,null,null,null,null,null,null,true]],\\"//www.google.com/maps/vt/data\\\\u003dEyH7OG3SikxJedyoLuG7nM_v3iZKpH-dHOXGr8E1VqUBeGb2YiYSJFENWzpvSkiBEHyvu-r2Ht_n3CxvwQyrkxlhf2kg5124kNXM8ppnVLf_K0hZbjOy_viUMiMWBIyTDggSdKLqrnoBsGM2MMX9p9BL6hXCeDFgkdsiKtV6qbJAw9XLMiRczvtEat3yYQ\\"],null,null,\\"PK\\",null,null,null,null,null,false,null,null,null,null,\\"en\\",null,null,null,null,[]]"],["wrb.fr",null,"[null,[\\"c_906b773f4a219e58\\",\\"r_5f7601c914ddb8f0\\"],[[\\"Are cats very friendly?\\",4],[\\"What are cats love?\\",4]],null,[[\\"rc_5fb47a5dae51748c\\",[\\"Here are images featuring cats:\\\\n\\\\n**A tabby cat curled up on a blanket.**\\\\n\\\\nhttp://googleusercontent.com/image_generation_content/1\\\\n\\\\n\\"],[],null,null,null,null,null,[2],\\"en\\",null,null,[null,null,null,null,null,null,[2],[[[[null,null,null,[null,1,null,\\"https://lh3.googleusercontent.com/gg/AJIvXiscNUrEE70t7X3CbpBodD0M3PE7GBFXTf4v22OpU9y0hYT-sMKISC3dUOZwS5NN04IfXmjzhjrpnxodQG6mpQGZSGp_jjexB_hUITh3rXTvGhsaJ2S7dIRRYN2oRrMJ9O-Z_RouBIfgL78-1t3GU5J3YeyxlIOboNOx4w3d9cXEVGi-MHmR\\",null,\\"ClsKNAowMDAwNjIxN2M1ZTg0ODQ4MTAyMjc4NDE1YmIwMzJmMGVlNTNkNTE4YmYzNjgzNDk2EAUaIzkxNDI4NDcwNTk3NDY0OTE0MzE1OWJjMTE3Y2EwZjExNTA4EAFIAlIMCMG07rYGENHDkNwBYglpbWFnZS9wbmc\\\\u003d\\",null,null,2,[1725667905,461644241],null,\\"image/png\\"]],[\\"http://googleusercontent.com/image_generation_content/1\\",0,null,\\"\\\\u003cextensions-ui\\\\u003ehttp://googleusercontent.com/image_generation_content/0\\\\u003c/extensions-ui\\\\u003e\\",\\"IMAGE_GENERATOR_JUNO_3B_DISTILLED\\"],null,[11,null,[null,[\\"image-gen/juno:v1-3b-lmroot\\",null,null,10,1,\\"bard_juno_v1_3b_distilled_1_1\\"]],null,[\\"en\\",\\"PK\\"],[\\"A tabby cat with beautiful eyes, curled up asleep on a soft blanket in a cozy, sunlit living room.\\",\\"A fluffy Persian cat with long, flowing fur, staring intently at a bird outside a window, captured in a closeup portrait.\\",\\"A sleek black cat with piercing yellow eyes, perched on a high fence overlooking a bustling city street, shot with a shallow depth of field.\\",\\"A playful ginger cat with a white chest, batting around a crumpled paper ball, captured in a dynamic motion blur, against a blurred background of autumn leaves.\\"],2540039070,null,0.9937883,\\"A cat\\",[[\\"A sleek black cat with piercing yellow eyes, perched on a high fence overlooking a bustling city street, shot with a shallow depth of field.\\",\\"VNLI score: 0.992345\\",null,3],[\\"A playful ginger cat with a white chest, batting around a crumpled paper ball, captured in a dynamic motion blur, against a blurred background of autumn leaves.\\",\\"VNLI score: 0.992345\\",null,3],[\\"A fluffy Persian cat with long, flowing fur, staring intently at a bird outside a window, captured in a closeup portrait.\\",\\"VNLI score: 0.987768\\",null,3]],0,false,false],null,true,null,false,\\"649464f3-dfc0-46bf-abfe-462ea371f8c4\\"]],null,[false,true]]],null,null,null,null,null,null,null,null,[false],null,false,[]]],[\\"Jalalpur Jattan, Pakistan\\",\\"SWML_DESCRIPTION_FROM_YOUR_INTERNET_ADDRESS\\",false,[[[null,null,null,[[300,200],null,null,[[326284118,741504246],[326454442,741706506]]]]],[[2,null,null,null,null,[null,null,null,[[[326369280,741605376],1068.5302,1931574222,1,864863983]]]]],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[null,null,null,null,null,null,null,true]],\\"//www.google.com/maps/vt/data\\\\u003dEyH7OG3SikxJedyoLuG7nM_v3iZKpH-dHOXGr8E1VqUBeGb2YiYSJFENWzpvSkiBEHyvu-r2Ht_n3CxvwQyrkxlhf2kg5124kNXM8ppnVLf_K0hZbjOy_viUMiMWBIyTDggSdKLqrnoBsGM2MMX9p9BL6hXCeDFgkdsiKtV6qbJAw9XLMiRczvtEat3yYQ\\"],null,null,\\"PK\\",null,null,null,null,null,true,null,null,null,null,\\"en\\",null,null,null,true,[[[\\"image_generation\\"]]]]"],["wrb.fr",null,"[null,[\\"c_906b773f4a219e58\\",\\"r_5f7601c914ddb8f0\\"],null,null,null,null,null,null,null,null,[\\"Generate some pictures of cats\\"]]"],["wrb.fr",null,"[null,[\\"c_906b773f4a219e58\\",\\"r_5f7601c914ddb8f0\\"],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,\\"AwAAAAAAAAAQ4DUFz3Xz2P6vbSmdHBk\\"]"],["di",8558],["af.httprm",8558,"5221099449916251030",48]]'
MisfiT2020 commented 1 week ago

so this is the value of candidate. all the values are null.

['rc_5fb47a5dae51748c', ['Creating your image with Imagen 3...\n\n[Imagen of a fake image]'], [], None, None, None, None, None, [1], 'en', None, None, [None, None, None, None, None, None, [...], [...]], None, None, None, None, None, None, None, None, [False], None, False]

but when I tried to check the response.text for the request, it contains some links. here is the sample

')]}\'\n\n[["wrb.fr",null,"[null,[\\"c_906b773f4a219e58\\",\\"r_5f7601c914ddb8f0\\"],null,null,[[\\"rc_5fb47a5dae51748c\\",[\\"Creating your image with Imagen 3...\\\\n\\\\n[Imagen of a fake image]\\"],[],null,null,null,null,null,[1],\\"en\\",null,null,[null,null,null,null,null,null,[3],[[[null,[\\"[Imagen of a fake image]\\",null,null,null,null,2,null,null,true],null,[],null,true]],null,[false,true]]],null,null,null,null,null,null,null,null,[false],null,false]],[\\"Jalalpur Jattan, Pakistan\\",\\"SWML_DESCRIPTION_FROM_YOUR_INTERNET_ADDRESS\\",false,[[[null,null,null,[[300,200],null,null,[[326284118,741504246],[326454442,741706506]]]]],[[2,null,null,null,null,[null,null,null,[[[326369280,741605376],1068.5302,1931574222,1,864863983]]]]],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[null,null,null,null,null,null,null,true]],\\"//www.google.com/maps/vt/data\\\\u003dEyH7OG3SikxJedyoLuG7nM_v3iZKpH-dHOXGr8E1VqUBeGb2YiYSJFENWzpvSkiBEHyvu-r2Ht_n3CxvwQyrkxlhf2kg5124kNXM8ppnVLf_K0hZbjOy_viUMiMWBIyTDggSdKLqrnoBsGM2MMX9p9BL6hXCeDFgkdsiKtV6qbJAw9XLMiRczvtEat3yYQ\\"],null,null,\\"PK\\",null,null,null,null,null,false,null,null,null,null,\\"en\\",null,null,null,null,[]]"],["wrb.fr",null,"[null,[\\"c_906b773f4a219e58\\",\\"r_5f7601c914ddb8f0\\"],[[\\"Are cats very friendly?\\",4],[\\"What are cats love?\\",4]],null,[[\\"rc_5fb47a5dae51748c\\",[\\"Here are images featuring cats:\\\\n\\\\n**A tabby cat curled up on a blanket.**\\\\n\\\\nhttp://googleusercontent.com/image_generation_content/1\\\\n\\\\n\\"],[],null,null,null,null,null,[2],\\"en\\",null,null,[null,null,null,null,null,null,[2],[[[[null,null,null,[null,1,null,\\"https://lh3.googleusercontent.com/gg/AJIvXiscNUrEE70t7X3CbpBodD0M3PE7GBFXTf4v22OpU9y0hYT-sMKISC3dUOZwS5NN04IfXmjzhjrpnxodQG6mpQGZSGp_jjexB_hUITh3rXTvGhsaJ2S7dIRRYN2oRrMJ9O-Z_RouBIfgL78-1t3GU5J3YeyxlIOboNOx4w3d9cXEVGi-MHmR\\",null,\\"ClsKNAowMDAwNjIxN2M1ZTg0ODQ4MTAyMjc4NDE1YmIwMzJmMGVlNTNkNTE4YmYzNjgzNDk2EAUaIzkxNDI4NDcwNTk3NDY0OTE0MzE1OWJjMTE3Y2EwZjExNTA4EAFIAlIMCMG07rYGENHDkNwBYglpbWFnZS9wbmc\\\\u003d\\",null,null,2,[1725667905,461644241],null,\\"image/png\\"]],[\\"http://googleusercontent.com/image_generation_content/1\\",0,null,\\"\\\\u003cextensions-ui\\\\u003ehttp://googleusercontent.com/image_generation_content/0\\\\u003c/extensions-ui\\\\u003e\\",\\"IMAGE_GENERATOR_JUNO_3B_DISTILLED\\"],null,[11,null,[null,[\\"image-gen/juno:v1-3b-lmroot\\",null,null,10,1,\\"bard_juno_v1_3b_distilled_1_1\\"]],null,[\\"en\\",\\"PK\\"],[\\"A tabby cat with beautiful eyes, curled up asleep on a soft blanket in a cozy, sunlit living room.\\",\\"A fluffy Persian cat with long, flowing fur, staring intently at a bird outside a window, captured in a closeup portrait.\\",\\"A sleek black cat with piercing yellow eyes, perched on a high fence overlooking a bustling city street, shot with a shallow depth of field.\\",\\"A playful ginger cat with a white chest, batting around a crumpled paper ball, captured in a dynamic motion blur, against a blurred background of autumn leaves.\\"],2540039070,null,0.9937883,\\"A cat\\",[[\\"A sleek black cat with piercing yellow eyes, perched on a high fence overlooking a bustling city street, shot with a shallow depth of field.\\",\\"VNLI score: 0.992345\\",null,3],[\\"A playful ginger cat with a white chest, batting around a crumpled paper ball, captured in a dynamic motion blur, against a blurred background of autumn leaves.\\",\\"VNLI score: 0.992345\\",null,3],[\\"A fluffy Persian cat with long, flowing fur, staring intently at a bird outside a window, captured in a closeup portrait.\\",\\"VNLI score: 0.987768\\",null,3]],0,false,false],null,true,null,false,\\"649464f3-dfc0-46bf-abfe-462ea371f8c4\\"]],null,[false,true]]],null,null,null,null,null,null,null,null,[false],null,false,[]]],[\\"Jalalpur Jattan, Pakistan\\",\\"SWML_DESCRIPTION_FROM_YOUR_INTERNET_ADDRESS\\",false,[[[null,null,null,[[300,200],null,null,[[326284118,741504246],[326454442,741706506]]]]],[[2,null,null,null,null,[null,null,null,[[[326369280,741605376],1068.5302,1931574222,1,864863983]]]]],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[null,null,null,null,null,null,null,true]],\\"//www.google.com/maps/vt/data\\\\u003dEyH7OG3SikxJedyoLuG7nM_v3iZKpH-dHOXGr8E1VqUBeGb2YiYSJFENWzpvSkiBEHyvu-r2Ht_n3CxvwQyrkxlhf2kg5124kNXM8ppnVLf_K0hZbjOy_viUMiMWBIyTDggSdKLqrnoBsGM2MMX9p9BL6hXCeDFgkdsiKtV6qbJAw9XLMiRczvtEat3yYQ\\"],null,null,\\"PK\\",null,null,null,null,null,true,null,null,null,null,\\"en\\",null,null,null,true,[[[\\"image_generation\\"]]]]"],["wrb.fr",null,"[null,[\\"c_906b773f4a219e58\\",\\"r_5f7601c914ddb8f0\\"],null,null,null,null,null,null,null,null,[\\"Generate some pictures of cats\\"]]"],["wrb.fr",null,"[null,[\\"c_906b773f4a219e58\\",\\"r_5f7601c914ddb8f0\\"],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,\\"AwAAAAAAAAAQ4DUFz3Xz2P6vbSmdHBk\\"]"],["di",8558],["af.httprm",8558,"5221099449916251030",48]]'

managed to find any sol?

HanaokaYuzu commented 1 week ago

Have pushed a fix, please update to the latest version and test it out. Thanks for the information provided.