Spaces:
Sleeping
Sleeping
File size: 1,325 Bytes
b00ea09 b1c5a53 3837055 b1c5a53 |
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 |
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)
|