import streamlit as st import google.generativeai as genai # Configure Gemini API genai.configure(api_key='AIzaSyCgfXYWyJjK8YrApUjO6433P3WAdpwQi0Y') 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)}" # Initialize session state for conversation history if 'conversation' not in st.session_state: st.session_state.conversation = [] st.title("🦷🦷Gemini QA System🦷🦷") st.write("Ask a question and get an answer from Gemini AI.") # User input user_message = st.text_input("Enter your question here...") if st.button("Submit"): if user_message: response = generate_response(user_message) st.session_state.conversation.append((user_message, response)) # Display conversation history if st.session_state.conversation: st.write("### Conversation History") for i, (question, answer) in enumerate(st.session_state.conversation): st.write(f"**Q{i+1}:** {question}") st.write(f"**A{i+1}:** {answer}") # Examples in the sidebar 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): response = generate_response(example) st.session_state.conversation.append((example, response))