Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +45 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import google.generativeai as genai
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import os
|
5 |
+
load_dotenv()
|
6 |
+
|
7 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
8 |
+
|
9 |
+
st.title("Chat - Gemini Bot")
|
10 |
+
|
11 |
+
model = genai.GenerativeModel(
|
12 |
+
model_name="gemini-pro"
|
13 |
+
)
|
14 |
+
|
15 |
+
if "messages" not in st.session_state:
|
16 |
+
st.session_state.messages = [
|
17 |
+
{
|
18 |
+
"role": "assistant",
|
19 |
+
"content": "Ask me anything"
|
20 |
+
}
|
21 |
+
]
|
22 |
+
|
23 |
+
for message in st.session_state.messages:
|
24 |
+
with st.chat_message(message['role']):
|
25 |
+
st.markdown(message['content'])
|
26 |
+
|
27 |
+
def llm_function(query):
|
28 |
+
response = model.generate_content(query)
|
29 |
+
with st.chat_message("assistant"):
|
30 |
+
st.markdown(response.text)
|
31 |
+
|
32 |
+
st.session_state.messages.append(
|
33 |
+
{
|
34 |
+
"role": "assistant",
|
35 |
+
"content": response.text
|
36 |
+
}
|
37 |
+
)
|
38 |
+
|
39 |
+
query = st.chat_input("Type your query here...")
|
40 |
+
|
41 |
+
if query:
|
42 |
+
with st.chat_message("user"):
|
43 |
+
st.markdown(query)
|
44 |
+
|
45 |
+
llm_function(query=query)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
google-generativeai
|
2 |
+
streamlit
|
3 |
+
python-dotenv
|