Spaces:
Runtime error
Runtime error
Commit
·
96e098a
1
Parent(s):
0ac6477
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import streamlit as st
|
|
3 |
from google.generativeai import GenerativeModel
|
4 |
|
5 |
# Set API key as an environment variable
|
6 |
-
os.environ['GOOGLE_API_KEY'] = "
|
7 |
|
8 |
# Create chatbot interface
|
9 |
st.title("Gemini API Chatbot")
|
@@ -16,27 +16,27 @@ user_input = st.text_input("You")
|
|
16 |
|
17 |
# Check if user input is not empty
|
18 |
if user_input:
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
-
|
|
|
3 |
from google.generativeai import GenerativeModel
|
4 |
|
5 |
# Set API key as an environment variable
|
6 |
+
os.environ['GOOGLE_API_KEY'] = "YOUR_GEMINI_API_KEY_HERE"
|
7 |
|
8 |
# Create chatbot interface
|
9 |
st.title("Gemini API Chatbot")
|
|
|
16 |
|
17 |
# Check if user input is not empty
|
18 |
if user_input:
|
19 |
+
# Add user message to chat history
|
20 |
+
chat_history.append(user_input)
|
21 |
|
22 |
+
# Display user message with markdown
|
23 |
+
st.markdown(f"**You:** {user_input}")
|
24 |
|
25 |
+
# Create model object
|
26 |
+
model = GenerativeModel(model_name="gemini-pro")
|
27 |
|
28 |
+
# Get model response with generate_content method
|
29 |
+
with st.spinner("Thinking..."):
|
30 |
+
response = model.generate_content(chat_history)
|
31 |
|
32 |
+
# Get response text from response object
|
33 |
+
response_text = response.contents[-1].parts[0].text
|
34 |
|
35 |
+
# Add response message to chat history
|
36 |
+
chat_history.append(response_text)
|
37 |
|
38 |
+
# Display response message with markdown
|
39 |
+
st.markdown(f"**Gemini Bot:** {response_text}")
|
40 |
|
41 |
+
# Update session state with chat history
|
42 |
+
st.session_state["chat_history"] = chat_history
|