Skip to content

Commit e4f6a0c

Browse files
Update DarkGPT.py
1 parent 9f48816 commit e4f6a0c

File tree

1 file changed

+10
-38
lines changed

1 file changed

+10
-38
lines changed

pages/DarkGPT.py

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import streamlit as st
2-
32
import sqlite3
43
from utils.get_response import (
54
get_bot_response,
@@ -8,12 +7,11 @@
87
)
98
import csv
109
import os
11-
# import pyttsx3
12-
# import pyperclip
1310

1411

1512
st.set_page_config(page_title="DarkGPT", page_icon="random", layout="wide", initial_sidebar_state="expanded")
1613

14+
1715
def local_css(file_name):
1816
with open(file_name) as f:
1917
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
@@ -33,7 +31,7 @@ def local_css(file_name):
3331
except Exception as e:
3432
st.error(f"An error occurred: {e}")
3533

36-
# Streamlit app
34+
3735
def main():
3836
try:
3937
if "chat_history" not in st.session_state:
@@ -42,20 +40,6 @@ def main():
4240
if "conversation_id" not in st.session_state:
4341
st.session_state.conversation_id = 1
4442

45-
provider = {
46-
47-
48-
}
49-
50-
51-
models = {
52-
"🚀 Airoboros 70B": "airoboros-70b",
53-
"🔮 Gemini Pro": "gemini-pro",
54-
"👑 Gemini 1.0 pro": "gemini-1.0-pro",
55-
"🧨 Gemini 1.0 Pro 001": "gemini-1.0-pro-001",
56-
"⚡ Gemini 1.0 pro latest": "gemini-1.0-pro-latest"
57-
}
58-
5943
columns = st.columns(3) # Split the layout into three columns
6044

6145
with columns[1]:
@@ -70,7 +54,6 @@ def main():
7054
st.page_link(page='app.py', label='Back to Home', icon='🏠')
7155
st.page_link(page='pages/Summarize.py', label='Summarize', icon='📝')
7256

73-
7457
# Sidebar (left side) - New chat button
7558
if st.sidebar.button("✨ New Chat", key="new_chat_button"):
7659
st.session_state.chat_history.clear()
@@ -106,37 +89,25 @@ def main():
10689
st.session_state.chat_history.append({"role": "user", "content": user_input})
10790
st.session_state.chat_history.append({"role": "bot", "content": bot_response})
10891

109-
# Store chat in the database
11092
for chat in st.session_state.chat_history:
11193
c.execute("INSERT INTO chat_history VALUES (?, ?, ?)",
112-
(st.session_state.conversation_id, chat["role"], chat["content"]))
94+
(st.session_state.conversation_id, chat["role"], chat["content"]))
11395
conn.commit()
11496

115-
# Display chat history
97+
# Display chat history
11698
for index, chat in enumerate(st.session_state.chat_history):
117-
with st.chat_message(chat["role"]):
118-
if chat["role"] == "user":
119-
st.markdown(chat["content"])
120-
elif chat["role"] == "bot":
121-
st.markdown(chat["content"])
99+
with st.chat_message(chat["role"]):
100+
if chat["role"] == "user":
101+
st.markdown(chat["content"])
102+
elif chat["role"] == "bot":
103+
st.markdown(chat["content"])
122104

123105
except Exception as e:
124106
st.error(f"An error occurred: {e}")
125107

126-
127108
except Exception as e:
128109
st.error(f"An error occurred: {e}")
129110

130-
# def export_to_csv(chat_history):
131-
# filename = "chat_history.csv"
132-
# latest_conversation = chat_history[-2:] # Get only the latest conversation
133-
# with open(filename, "a+", newline="") as csvfile:
134-
# fieldnames = ["User Input", "Bot Response"]
135-
# writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
136-
# if csvfile.tell() == 0: # Check if the file is empty
137-
# writer.writeheader() # Write header if file is empty
138-
# if len(latest_conversation) == 2: # Check if the latest conversation is complete
139-
# writer.writerow({"User Input": latest_conversation[0]["content"], "Bot Response": latest_conversation[1]["content"]})
140111

141112
def display_conversation(conversation_id):
142113
c.execute("SELECT * FROM chat_history WHERE conversation_id=?", (conversation_id,))
@@ -146,5 +117,6 @@ def display_conversation(conversation_id):
146117
st.markdown(f"{chat[1]}")
147118
st.markdown(f"{chat[2]}")
148119

120+
149121
if __name__ == "__main__":
150122
main()

0 commit comments

Comments
 (0)