Git Product home page Git Product logo

Comments (4)

bluemods avatar bluemods commented on June 2, 2024

I'm currently working through it but it seems like the images are returned normally, and they start with
https://lh3.googleusercontent.com/bard/
To access the content however you need to pass your account.google.com cookies, or you get 403 forbidden errors.

A working prompt to trigger them is generate an image of a cat etc.

from bard-api.

raymerjacque avatar raymerjacque commented on June 2, 2024

Thank you, however i am a little lost here. can you point me to the code i need to add or edit in my fastapi script ?

for example here is my fastapi script :


@app.post("/api/ask", response_model=ResponseModel)
def get_response(user_input: UserInput):
    try:
    
        # Load .env file for each request and overwrite existing variables
        load_dotenv(override=True)

        # Get BARD_API_KEY from the .env file
        BARD_API_KEY = os.environ.get('BARD_API_KEY')

        # Set up the session for each request
        session = requests.Session()
        session.headers = {
            "Host": "gemini.google.com",
            "X-Same-Domain": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
            "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
            "Origin": "https://gemini.google.com",
            "Referer": "https://gemini.google.com/",
        }
        session.cookies.set("__Secure-1PSID", BARD_API_KEY)

        bard = Bard(token=BARD_API_KEY, session=session, timeout=30)
            
        # Print the user input to the console
        print(f"Received user input: {user_input.user_input}")    
        response = process_input(user_input.user_input, bard)
        # Save response to a temporary file
        temp_file_path = save_response_to_file(response)
        # Return the path of the temporary file instead of the response content
        return {"content": temp_file_path}        
        
        print(f"Response saved to: {temp_file_path}")  # For debugging
        return response
    except Exception as e:
        # Log the error details for debugging
        print(f"Error: {e}")
        # You might want to return a more generic error message in a production environment
        raise HTTPException(status_code=400, detail=f"Error processing request: {e}")
        
def save_response_to_file(response):
    # Define the desired directory path
    directory_path = '/www/html/temp/'

    # Ensure the directory exists, if not, create it
    os.makedirs(directory_path, exist_ok=True)

    # Create a unique file name. You can also use other methods to generate unique names
    file_name = f"response_{int(time.time())}.json"
    file_path = os.path.join(directory_path, file_name)

    # Write the response to the file
    with open(file_path, 'w') as file:
        json.dump(response, file)

    return file_path      

def process_input(user_input, bard):
    response = bard.get_answer(user_input)
    result = {
        'content': response['content'],
        'images': list(response['images']) if 'images' in response and isinstance(response['images'], set) else response.get('images', []),
        'links': list(response['links']) if 'links' in response and isinstance(response['links'], set) else response.get('links', [])
    }

    return result

I am unsure what code to change or edit, it does not generate images, if i ask it to generate an image it simply tells me it cant. normal text generations works fine, urls work fine as well. if i ask it to show me images it does, it sends links. but it doesnt generate images.

any assistance is welcomed, thank you.

from bard-api.

raymerjacque avatar raymerjacque commented on June 2, 2024

Any progress on image generation ?

from bard-api.

dsdanielpark avatar dsdanielpark commented on June 2, 2024

[NOTICE] Please, go to Gemini-API https://github.com/dsdanielpark/Gemini-API

Gemini Icon Google - Gemini API

A unofficial Python wrapper, python-gemini-api, operates through reverse-engineering, utilizing cookie values to interact with Google Gemini for users struggling with frequent authentication problems or unable to authenticate via Google Authentication.

Collaborated competently with Antonio Cheong.

What is Gemini?

[Paper] [Official Website] [Official API] [API Documents]

Gemini is a family of generative AI models developed by Google DeepMind that is designed for multimodal use cases. The Gemini API gives you access to the Gemini Pro and Gemini Pro Vision models. In February 2024, Google's Bard service was changed to Gemini.


Installation

pip install python-gemini-api
pip install git+https://github.com/dsdanielpark/Gemini-API.git

For the updated version, use as follows:

pip install -q -U python-gemini-api

from bard-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.