Spaces:
Sleeping
Sleeping
Roberta2024
commited on
Commit
•
f979626
1
Parent(s):
280a54d
Update app.py
Browse files
app.py
CHANGED
@@ -2,14 +2,14 @@ import streamlit as st
|
|
2 |
import google.generativeai as genai
|
3 |
|
4 |
# Configure Gemini API
|
5 |
-
genai.configure(api_key='
|
6 |
model = genai.GenerativeModel('gemini-pro')
|
7 |
|
8 |
def generate_response(user_message):
|
9 |
try:
|
10 |
# Use Gemini API to generate a response
|
11 |
response = model.generate_content(user_message)
|
12 |
-
|
13 |
# Check if the response has text
|
14 |
if response.text:
|
15 |
return response.text
|
@@ -18,33 +18,33 @@ def generate_response(user_message):
|
|
18 |
except Exception as e:
|
19 |
return f"An error occurred: {str(e)}"
|
20 |
|
21 |
-
#
|
22 |
-
|
|
|
|
|
23 |
st.title("Gemini QA System")
|
24 |
st.write("Ask a question and get an answer from Gemini AI.")
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
if
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
]
|
45 |
-
for
|
46 |
-
if st.button(
|
47 |
-
|
48 |
-
|
49 |
-
st.subheader("Gemini's Response:")
|
50 |
-
st.write(response)
|
|
|
2 |
import google.generativeai as genai
|
3 |
|
4 |
# Configure Gemini API
|
5 |
+
genai.configure(api_key='AIzaSyBIPYXqIvI1X6unKTbuWqcVfNFCePr8_sQ')
|
6 |
model = genai.GenerativeModel('gemini-pro')
|
7 |
|
8 |
def generate_response(user_message):
|
9 |
try:
|
10 |
# Use Gemini API to generate a response
|
11 |
response = model.generate_content(user_message)
|
12 |
+
|
13 |
# Check if the response has text
|
14 |
if response.text:
|
15 |
return response.text
|
|
|
18 |
except Exception as e:
|
19 |
return f"An error occurred: {str(e)}"
|
20 |
|
21 |
+
# Initialize session state for conversation history
|
22 |
+
if 'conversation' not in st.session_state:
|
23 |
+
st.session_state.conversation = []
|
24 |
+
|
25 |
st.title("Gemini QA System")
|
26 |
st.write("Ask a question and get an answer from Gemini AI.")
|
27 |
|
28 |
+
# User input
|
29 |
+
user_message = st.text_input("Enter your question here...")
|
30 |
+
|
31 |
+
if st.button("Submit"):
|
32 |
+
if user_message:
|
33 |
+
response = generate_response(user_message)
|
34 |
+
st.session_state.conversation.append((user_message, response))
|
35 |
+
|
36 |
+
# Display conversation history
|
37 |
+
if st.session_state.conversation:
|
38 |
+
st.write("### Conversation History")
|
39 |
+
for i, (question, answer) in enumerate(st.session_state.conversation):
|
40 |
+
st.write(f"**Q{i+1}:** {question}")
|
41 |
+
st.write(f"**A{i+1}:** {answer}")
|
42 |
+
|
43 |
+
# Examples in the sidebar
|
44 |
+
st.sidebar.title("Examples")
|
45 |
+
st.sidebar.write("Click on an example to use it:")
|
46 |
+
examples = ["What is the capital of France?", "Explain quantum computing in simple terms."]
|
47 |
+
for example in examples:
|
48 |
+
if st.sidebar.button(example):
|
49 |
+
response = generate_response(example)
|
50 |
+
st.session_state.conversation.append((example, response))
|
|
|
|