- [Solved] Filter langchain vector database using as_retriever search_kwargs parameter
- [Solved] ModuleNotFoundError: No module named 'llama_index.graph_stores'
- Best AI Text Generators for High Quality Content Writing
- Tensorflow Error on Macbook M1 Pro - NotFoundError: Graph execution error
- How does GPT-like transformers utilize only the decoder to do sequence generation?
- How to set all tensors to cuda device?
- How should I use torch.compile properly?
- How do I check if PyTorch is using the GPU?
- WARNING:tensorflow:Using a while_loop for converting cause there is no registered converter for this op
- How to use OneCycleLR?
- Error in Python script "Expected 2D array, got 1D array instead:"?
- How to save model in .pb format and then load it for inference in Tensorflow?
- Top 6 AI Logo Generator Up Until Now- Smarter Than Midjourney
- Best 9 AI Story Generator Tools
- The Top 6 AI Voice Generator Tools
- Best AI Low Code/No Code Tools for Rapid Application Development
- YOLOV8 how does it handle different image sizes
- Best AI Tools For Email Writing & Assistants
- 8 Data Science Competition Platforms Beyond Kaggle
- Data Analysis Books that You Can Buy
How to Disable Safety Settings in Gemini Vision Pro Model Using API?
Written by- Aionlinecourse458 times views
Gemini Vision Pro is a powerful computer vision model developed by Google Deepminnd. Gemini Vision Pro has a lot of uses and real-time applications in recent times. This vision model provides various safety settings to prevent misuse. However, sometimes developers need to disable these safety settings because of some specific application.
Solution 1:
We can modify the safety setting of the Gemini Vision Pro model as described below:
safe = [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE",
},
]
Solution 2:
We may have to try few times in a loop because sometimes Gemini through errors:
def generate_content_with_gemini_from_text(prompt):
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
generation_config=generation_config,
safety_settings = safe
)
e = None # Initialize e before the try-except block
for attempt in range(4):
try:
response = model.generate_content(prompt)
return response.text
except Exception as caught_exception:
e = caught_exception # Update e with the caught exception
print(f"Error on attempt {attempt + 1}: {e}")
time.sleep(1)
if e:
print(f"Failed after 4 retries. Error: {e}")
else:
print("Failed after 4 retries due to an unknown error.")
return None
We need to send correctly formatted post requests through Gemini Vision Pro API to disable the safety settings. We must check that the request includes the necessary headers and payload. By handling the response properly, we can ensure that the safety settings are disabled. These approaches help us to disable the safety settings of the Gemini Vision Pro model using its API.Thank you for reading the article.