|
import streamlit as st |
|
import google.generativeai as genai |
|
|
|
|
|
genai.configure(api_key='AIzaSyCgfXYWyJjK8YrApUjO6433P3WAdpwQi0Y') |
|
model = genai.GenerativeModel('gemini-pro') |
|
|
|
def generate_response(user_message): |
|
try: |
|
|
|
response = model.generate_content(user_message) |
|
|
|
|
|
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)}" |
|
|
|
|
|
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_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)) |
|
|
|
|
|
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}") |
|
|
|
|
|
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)) |