Rahul-Sahani04 / Gemini-Pro-Vision-Chatbot

Gemini Pro AI is a Streamlit-powered application leveraging Google's Generative AI API. Engage in dynamic text and image-based conversations with Gemini Pro and Gemini Pro Vision models. Simply input text or upload images to receive contextual and creative responses. Explore the possibilities of conversational AI with Gemini Pro AI.
https://gemini-pro-vision-chatbot.streamlit.app/
1 stars 0 forks source link

I made the chatbot feel a little bit more interactive you can add this part #1

Open ChiragNSundar opened 5 months ago

ChiragNSundar commented 5 months ago

load_dotenv() api_key = os.getenv("GENAI_API_KEY")

    if not api_key:
        api_key = st.secrets["GENAI_API_KEY"]
        if not api_key:
            st.error("Please set the GENAI_API_KEY environment variable.")
            st.stop()

    genai.configure(api_key=api_key)

    # Set up the model
    generation_config = {
        "temperature": 0.9,
        "top_p": 1,
        "top_k": 32,
        "max_output_tokens": 8192,
    }

    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",
        generation_config=generation_config,
        safety_settings=safety_settings,
    )

    # Load conversation history from file
    with open("conversation_history.json", "r") as file:
        conversation_history = json.load(file)

    # Start a chat with a greeting and initial information
    convo = model.start_chat(history=conversation_history)

    st.title("Mental Support Chatbot")

    # Get user input
    user_input = st.text_input("You:", key="user_input", placeholder="Type your message...")

    if user_input:
        with st.spinner("Thinking..."):
            convo.send_message(user_input)
            bot_response = convo.last.text

        # Display user message on the right
        message(user_input, is_user=True, key="user_message")

        # Display bot response on the left
        message(bot_response, is_user=False, key="bot_message")

WhatsApp Image 2024-06-15 at 16 42 13