Spaces:
Sleeping
Sleeping
File size: 1,723 Bytes
932eaf2 3c1e1ad 932eaf2 f979626 932eaf2 f979626 bc9ad07 932eaf2 f979626 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import streamlit as st
import google.generativeai as genai
# Configure Gemini API
genai.configure(api_key='AIzaSyBpp_F2XhYPCJFh8FNH3kTRwPhpW_anuJE')
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))
|