Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import google.generativeai as genai | |
| from PIL import Image | |
| from io import BytesIO | |
| # Set up your API key and model | |
| genai.configure(api_key="AIzaSyD-61G3GhSY97O-X2AlpXGv1MYBBMRFmwg") | |
| generation_config = { | |
| "temperature": 0.4, | |
| "top_p": 1, | |
| "top_k": 32, | |
| "max_output_tokens": 4096, | |
| } | |
| safety_settings = [ | |
| {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| ] | |
| model = genai.GenerativeModel( | |
| model_name="gemini-pro-vision", | |
| generation_config=generation_config, | |
| safety_settings=safety_settings, | |
| ) | |
| def process_image(image_bytes): | |
| image_parts = [ | |
| {"mime_type": "image/png", "data": image_bytes} | |
| ] | |
| prompt_parts = [ | |
| "Identify whether an AI-generated content is present in the screen or not. If yes, elaborate about the content and give reasons for it.\n\n", | |
| image_parts[0], | |
| ] | |
| response = model.generate_content(prompt_parts) | |
| return response.text | |
| st.title("Image Validation") | |
| uploaded_file = st.file_uploader("Choose an image...", type="png") | |
| if uploaded_file is not None: | |
| st.image(uploaded_file, caption="Uploaded Image.", use_column_width=True) | |
| st.write("") | |
| st.write("Analyzing...") | |
| # Process the image and display the response | |
| image_bytes = uploaded_file.read() | |
| response_text = process_image(image_bytes) | |
| st.write(response_text) | |