import os import google.generativeai as genai import gradio as gr genai.configure(api_key="AIzaSyBYwBXI_qd4CL-xb8e39R_akVzWzVSHkhA") generation_config = { "temperature": 1, "top_p": 0.95, "top_k": 0, "max_output_tokens": 100, } 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-1.5-pro-latest", generation_config=generation_config, safety_settings=safety_settings ) # Start a chat session chat_session = model.start_chat(history=[]) def chatbot(user_message): # Send user message to the chat session response = chat_session.send_message(user_message) return response.text # Define the Gradio interface with a text input and text output interface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="GenAI Chatbot") # Launch the Gradio interface interface.launch(share=True)