import streamlit as st import google.generativeai as genai import os api_key = os.getenv('GENAI_API_KEY') def generate_with_gemini(prompt): genai.configure(api_key=api_key) # Set up the model configuration generation_config = { "temperature": 0.9, "top_p": 1, "top_k": 1, "max_output_tokens": 2048, } 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" }, ] # Initialize the model model = genai.GenerativeModel(model_name="gemini-1.0-pro", generation_config=generation_config, safety_settings=safety_settings) # Generate content response = model.generate_content([prompt]) return response.text # Streamlit UI st.title('Gemini Model Content Generator') prompt = st.text_area("Enter your prompt here:", "Enter prompt here") if st.button('Generate'): with st.spinner('Generating...'): generated_content = generate_with_gemini(prompt) st.text_area("Generated Content:", generated_content, height=300)