-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (27 loc) · 944 Bytes
/
main.py
File metadata and controls
40 lines (27 loc) · 944 Bytes
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
from dotenv import load_dotenv
import os
load_dotenv()
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
model = genai.GenerativeModel("gemini-3.1-flash-lite-preview")
st.title("AI Chatbot")
if "message_list" not in st.session_state:
st.session_state["message_list"] = []
for message in st.session_state["message_list"]:
with st.chat_message(message["role"]):
st.write(message["content"])
user_text = st.chat_input("Write your message")
if user_text:
with st.chat_message("user"):
st.write(user_text)
st.session_state["message_list"].append(
{"role": "user", "content": user_text}
)
response = model.generate_content(user_text)
ai_text = response.text
with st.chat_message("assistant"):
st.write(ai_text)
st.session_state["message_list"].append(
{"role": "assistant", "content": ai_text}
)