from dotenv import load_dotenv load_dotenv() import os import google.generativeai as genai import gradio as gr # Configure Google Generative AI #genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) GOOGLE_API_KEY=os.environ.get("google_api_key") genai.configure(api_key=(GOOGLE_API_KEY)) # Set up the model with adjusted generation and safety settings generation_config = { "temperature": 0.95, # Higher temperature for more creative responses "top_p": 1, # Higher top_p for more diversity in responses "top_k": 1, # Higher top_k for more diversity in responses "max_output_tokens": 2048, # Maximum length of the generated text } safety_settings = [ { "category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_ONLY_HIGH" }, { "category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE" }, { "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_ONLY_HIGH" }, { "category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE" }, ] model = genai.GenerativeModel(model_name="gemini-1.0-pro", generation_config=generation_config, safety_settings=safety_settings) def get_gemini_responces(message, chat_history): # Prepend a contextual prompt to guide the model's responses as Jules Winnfield prompt = "answer this as if You are yoda, a character from the Star wars universe ,in first person : . " full_message = prompt + message # Generate the response responce = model.generate_content(full_message) # Append the model's response to the chat history chat_history.append((message, responce.text)) return "", chat_history # Define your custom theme's CSS as a string custom_theme_css = """ .gradio-container { background: url(https://upload.wikimedia.org/wikipedia/en/9/9b/Yoda_Empire_Strikes_Back.png); color: #2b2514; /* Example text color */ /* Add more CSS properties as needed */ } """ # Define the Gradio interface with a Chatbot component and the specified theme with gr.Blocks(theme=gr.Theme.from_hub("HaleyCH/HaleyCH_Theme"), css=custom_theme_css) as demo: chatbot = gr.Chatbot() msg = gr.Textbox() clear = gr.ClearButton([msg, chatbot]) msg.submit(get_gemini_responces, [msg, chatbot], [msg, chatbot]) # Launch the Gradio app if __name__ == "__main__": demo.launch()