import streamlit as st import google.generativeai as genai # Configure Gemini API genai.configure(api_key='AIzaSyCFpgd3wBtKDYcr6k2mQcW21sxnoZ8oL90') model = genai.GenerativeModel('gemini-pro') def generate_response(user_message): try: # Use Gemini API to generate a response response = model.generate_content(user_message) # Check if the response has text if response.text: return response.text else: return "Error: The model generated an empty response." except Exception as e: return f"An error occurred: {str(e)}" # Streamlit UI st.title("🐹Gemini QA System🐹") st.write("Ask a question and get an answer from Gemini AI.") user_message = st.text_input("Enter your question here...") if st.button("Get Answer"): response = generate_response(user_message) st.text_area("Gemini's Response", value=response, height=200) # Examples st.sidebar.title("Examples") st.sidebar.write("Click on an example to use it:") examples = ["What is the capital of France?", "Explain quantum computing in simple terms."] for example in examples: if st.sidebar.button(example): st.session_state.user_message = example response = generate_response(example) st.text_area("Gemini's Response", value=response, height=200)