ytrsoymr commited on
Commit
443d575
·
verified ·
1 Parent(s): 1a13cad

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +35 -0
  2. config.py +20 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from chatbot.conversation import chat_bot
3
+ from chatbot.database import get_chat_history, save_chat
4
+
5
+
6
+ # Generate or retrieve session ID
7
+ from config import generate_session_id
8
+
9
+ if "session_id" not in st.session_state:
10
+ st.session_state.session_id = generate_session_id()
11
+
12
+ st.title("AI Chatbot")
13
+ st.write("Ask me anything!")
14
+
15
+ # Display chat history
16
+ history = get_chat_history(st.session_state.session_id)
17
+ for user_msg, bot_resp in history:
18
+ with st.chat_message("user"):
19
+ st.write(user_msg)
20
+ with st.chat_message("assistant"):
21
+ st.write(bot_resp)
22
+
23
+ # User input
24
+ user_input = st.chat_input("Type your message...")
25
+ if user_input:
26
+ response, session_id = chat_bot(user_input, st.session_state.session_id)
27
+
28
+ # Display messages in chat
29
+ with st.chat_message("user"):
30
+ st.write(user_input)
31
+ with st.chat_message("assistant"):
32
+ st.write(response)
33
+
34
+ # Save chat history
35
+ save_chat(session_id, user_input, response)
config.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ import uuid
4
+
5
+ # Load environment variables from a .env file
6
+ load_dotenv()
7
+
8
+ # Google GenAI API Key
9
+ GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
10
+
11
+ # SQLite Database File Path
12
+ DB_PATH = os.getenv("DB_PATH", "chats_data/sqlite.db") # Default file if not set
13
+
14
+ # LangChain Configuration
15
+ MODEL_NAME = "gemini-1.5-pro"
16
+ TEMP = 0.7 # Model temperature
17
+
18
+ # Function to generate a new session ID (UUID)
19
+ def generate_session_id():
20
+ return str(uuid.uuid4())
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ langchain
2
+ langchain_community
3
+ streamlit
4
+ python-dotenv
5
+ langchain_google_genai