Comments (4)
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.
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.
Any progress on image generation ?
from bard-api.
[NOTICE] Please, go to Gemini-API https://github.com/dsdanielpark/Gemini-API
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)
- ChatBard: token_from_browser HOT 9
- ImportError: cannot import name 'BardCookies' from partially initialized module 'bardapi' (most likely due to a circular import) HOT 6
- Some code errors in README examples , os module import HOT 4
- Bard __SECURE-1PSID does not match HOT 2
- Exception: SNlM0e value not found. Double-check __Secure-1PSID value or pass it as Bard(token='xxxxx') HOT 1
- Google changed the the way "__Secure-1PSID" looks, how to use this package effectively,the cookie values does not end in '.' period now HOT 8
- Multiple-Cookies has been changed. HOT 15
- Google renames its chatbot Bard to Gemini HOT 41
- Gemini Ultra? HOT 4
- TooManyRedirects: Exceeded 30 redirects. HOT 1
- Check out this Bard/Gemini project. HOT 2
- Google changed their __Secure-1PSID value stracture HOT 2
- ask_about_image Not working HOT 2
- Cookies refreshing very often and getting 429 all the time HOT 2
- How can automaticly get cookies value in no gui servers? HOT 2
- Please, go to Gemini-API `https://github.com/dsdanielpark/Gemini-API`
- a conversation towards getting advance AI HOT 1
- Reflection on the Bard API Project
- Connecting Geminei to Ads HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bard-api.