Spaces:
Runtime error
Runtime error
Upload 6 files
Browse files- app.py +166 -0
- chat_history.db +0 -0
- cookies.py +11 -0
- howtouse.md +56 -0
- requirements.txt +0 -0
- style.css +22 -0
app.py
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from g4f.client import Client
|
3 |
+
import sqlite3
|
4 |
+
import subprocess
|
5 |
+
import pyttsx3
|
6 |
+
import os
|
7 |
+
from cookies import *
|
8 |
+
from undetected_chromedriver import *
|
9 |
+
|
10 |
+
def local_css(file_name):
|
11 |
+
with open(file_name) as f:
|
12 |
+
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
13 |
+
|
14 |
+
local_css("style.css")
|
15 |
+
|
16 |
+
# Create a connection to the database
|
17 |
+
conn = sqlite3.connect('chat_history.db')
|
18 |
+
c = conn.cursor()
|
19 |
+
|
20 |
+
# Create table if not exists
|
21 |
+
try:
|
22 |
+
c.execute('''CREATE TABLE IF NOT EXISTS chat_history
|
23 |
+
(conversation_id INTEGER, role TEXT, content TEXT)''')
|
24 |
+
conn.commit()
|
25 |
+
except Exception as e:
|
26 |
+
st.error(f"An error occurred: {e}")
|
27 |
+
|
28 |
+
|
29 |
+
def copy(text):
|
30 |
+
"""
|
31 |
+
Copy text to clipboard on Windows.
|
32 |
+
|
33 |
+
Parameters:
|
34 |
+
text (str): The text to copy to the clipboard.
|
35 |
+
|
36 |
+
Returns:
|
37 |
+
bool: True if the text was successfully copied, False otherwise.
|
38 |
+
"""
|
39 |
+
try:
|
40 |
+
subprocess.run(['clip'], input=text.strip().encode('utf-16'), check=True)
|
41 |
+
return True
|
42 |
+
except subprocess.CalledProcessError:
|
43 |
+
st.error("Error: Unable to copy text to clipboard on Windows.")
|
44 |
+
return False
|
45 |
+
|
46 |
+
|
47 |
+
# Streamlit app
|
48 |
+
def main():
|
49 |
+
|
50 |
+
try:
|
51 |
+
if "chat_history" not in st.session_state:
|
52 |
+
st.session_state.chat_history = []
|
53 |
+
|
54 |
+
if "conversation_id" not in st.session_state:
|
55 |
+
st.session_state.conversation_id = 1
|
56 |
+
|
57 |
+
models = {
|
58 |
+
"🚀Airoboros 70B": "airoboros-70b",
|
59 |
+
"⚡GPT-4 Turbo": "gpt-4-turbo"
|
60 |
+
}
|
61 |
+
|
62 |
+
columns = st.columns(3) # Split the layout into three columns
|
63 |
+
with columns[0]:
|
64 |
+
st.header("DarkGPT")
|
65 |
+
|
66 |
+
with columns[2]:
|
67 |
+
selected_model_display_name = st.selectbox("Select Model", list(models.keys()), index=0)
|
68 |
+
|
69 |
+
with columns[1]:
|
70 |
+
selected_model = models[selected_model_display_name]
|
71 |
+
|
72 |
+
# Sidebar (left side) - New chat button
|
73 |
+
if st.sidebar.button("✨New Chat", key="new_chat_button"):
|
74 |
+
st.session_state.chat_history.clear()
|
75 |
+
st.session_state.conversation_id += 1
|
76 |
+
|
77 |
+
# Sidebar (left side) - Display saved chat
|
78 |
+
st.sidebar.write("Chat History")
|
79 |
+
c.execute("SELECT DISTINCT conversation_id FROM chat_history")
|
80 |
+
conversations = c.fetchall()
|
81 |
+
for conv_id in reversed(conversations):
|
82 |
+
c.execute("SELECT content FROM chat_history WHERE conversation_id=? AND role='bot' LIMIT 1",
|
83 |
+
(conv_id[0],))
|
84 |
+
first_bot_response = c.fetchone()
|
85 |
+
if first_bot_response:
|
86 |
+
if st.sidebar.button(" ".join(first_bot_response[0].split()[0:5])):
|
87 |
+
display_conversation(conv_id[0])
|
88 |
+
|
89 |
+
# Sidebar (left side) - Clear Chat History button
|
90 |
+
if st.sidebar.button("Clear Chat History ✖️"):
|
91 |
+
st.session_state.chat_history.clear()
|
92 |
+
c.execute("DELETE FROM chat_history")
|
93 |
+
conn.commit()
|
94 |
+
|
95 |
+
# Main content area (center)
|
96 |
+
st.markdown("---")
|
97 |
+
if selected_model == "gpt-4-turbo":
|
98 |
+
with st.chat_message("bot"):
|
99 |
+
st.markdown("Working with this model used the default model for generation.")
|
100 |
+
|
101 |
+
user_input = st.chat_input("Ask Anything ...")
|
102 |
+
|
103 |
+
# Listen for changes in user input and generate completion
|
104 |
+
if user_input:
|
105 |
+
client = Client()
|
106 |
+
response = client.chat.completions.create(
|
107 |
+
model=selected_model,
|
108 |
+
messages=[{"role": "user", "content": user_input}],
|
109 |
+
)
|
110 |
+
bot_response = response.choices[0].message.content
|
111 |
+
|
112 |
+
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
113 |
+
st.session_state.chat_history.append({"role": "bot", "content": bot_response})
|
114 |
+
|
115 |
+
# Store chat in the database
|
116 |
+
for chat in st.session_state.chat_history:
|
117 |
+
c.execute("INSERT INTO chat_history VALUES (?, ?, ?)",
|
118 |
+
(st.session_state.conversation_id, chat["role"], chat["content"]))
|
119 |
+
conn.commit()
|
120 |
+
|
121 |
+
# Display chat history
|
122 |
+
for index, chat in enumerate(st.session_state.chat_history):
|
123 |
+
with st.chat_message(chat["role"]):
|
124 |
+
if chat["role"] == "user":
|
125 |
+
st.markdown(chat["content"])
|
126 |
+
elif chat["role"] == "bot":
|
127 |
+
st.markdown(chat["content"])
|
128 |
+
col1 = st.columns(10)
|
129 |
+
with col1[0]:
|
130 |
+
copy_button = f"text_copy_{index}"
|
131 |
+
if st.button('📋', key=copy_button):
|
132 |
+
copy(chat["content"]) # Assuming chat["content"] contains the text to copy
|
133 |
+
|
134 |
+
# Add a speak button in the second column
|
135 |
+
with col1[1]:
|
136 |
+
speak_button = f"text_regenerate_{index}"
|
137 |
+
if st.button('🔊', key=speak_button):
|
138 |
+
engine = pyttsx3.init()
|
139 |
+
engine.say(chat["content"])
|
140 |
+
engine.runAndWait()
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
|
145 |
+
except Exception as e:
|
146 |
+
st.error(f"An error occurred: {e}")
|
147 |
+
|
148 |
+
except TimeoutError:
|
149 |
+
st.error("Check Your Internet Connection:")
|
150 |
+
|
151 |
+
except ConnectionError:
|
152 |
+
st.error("Check Your Internet Connection:")
|
153 |
+
|
154 |
+
except RuntimeError:
|
155 |
+
st.error("Check Your Internet Connection:")
|
156 |
+
|
157 |
+
def display_conversation(conversation_id):
|
158 |
+
c.execute("SELECT * FROM chat_history WHERE conversation_id=?", (conversation_id,))
|
159 |
+
chats = c.fetchall()
|
160 |
+
st.markdown(f"### Conversation")
|
161 |
+
for chat in chats:
|
162 |
+
st.markdown(f"{chat[1]}")
|
163 |
+
st.markdown(f"{chat[2]}")
|
164 |
+
|
165 |
+
if __name__ == "__main__":
|
166 |
+
main()
|
chat_history.db
ADDED
Binary file (16.4 kB). View file
|
|
cookies.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from g4f.cookies import set_cookies
|
2 |
+
|
3 |
+
set_cookies(".bing.com", {
|
4 |
+
"_clck": "w3y6fr%7C2%7Cfjl%7C0%7C1517"
|
5 |
+
})
|
6 |
+
set_cookies("chat.openai.com", {
|
7 |
+
"__cflb": "0H28vVfF4aAyg2hkHEuhVVUPGkAFmYvk57xoxRMRm1X"
|
8 |
+
})
|
9 |
+
set_cookies(".google.com", {
|
10 |
+
"__Secure-3PSID": "g.a000hQh_KYcwS81vIoGwzKsyOPzas0X1x5e-k5t1hP-yKs9Glr4Y3QvqZySWierihtij8oAHvgACgYKAcgSAQASFQHGX2Mi2gQjmlI3XdU3m8xFFwtpzRoVAUF8yKoOoZXsIMZcs3KirlD37H8A0076"
|
11 |
+
})
|
howtouse.md
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# GPT Chat Explorer
|
2 |
+
|
3 |
+
GPT Chat Explorer is an interactive web application that allows users to engage in conversations with various GPT (Generative Pre-trained Transformer) models in real-time. This repository contains the source code for the application.
|
4 |
+
|
5 |
+
## Features
|
6 |
+
|
7 |
+
- **Real-time Conversations:** Engage in natural conversations with GPT models and explore their responses in real-time.
|
8 |
+
- **Chat History:** Review and manage chat history organized by conversation ID for easy reference.
|
9 |
+
- **Model Selection:** Choose from a selection of GPT models, including GPT-3.5 Turbo, GPT-4, and more.
|
10 |
+
- **Custom Styling:** Customize the appearance of the app with custom CSS styles to suit your preferences.
|
11 |
+
- **Clear Chat History:** Easily clear chat history with a single click to start fresh.
|
12 |
+
- **Interactive Sidebar:** Access key functionalities such as starting a new chat and clearing chat history conveniently from the sidebar.
|
13 |
+
- **Error Handling:** Robust error handling ensures smooth operation and provides feedback in case of any issues.
|
14 |
+
- **Timestamped Conversations:** View conversation history with timestamps for each message, providing context and chronological order.
|
15 |
+
- **Responsive Design:** Enjoy a seamless experience across devices with responsive design elements.
|
16 |
+
|
17 |
+
## Getting Started
|
18 |
+
|
19 |
+
To get started with the GPT Chat Explorer, follow these steps:
|
20 |
+
|
21 |
+
1. **Clone the Repository:**
|
22 |
+
```
|
23 |
+
git clone https://github.com/codewithdark-git/DarkGPT-Chatbot.git
|
24 |
+
```
|
25 |
+
|
26 |
+
2. **Install Dependencies:**
|
27 |
+
```
|
28 |
+
pip install -r requirements.txt
|
29 |
+
```
|
30 |
+
|
31 |
+
3. **Run the Application:**
|
32 |
+
```
|
33 |
+
streamlit run app.py
|
34 |
+
```
|
35 |
+
|
36 |
+
4. **Start Chatting:**
|
37 |
+
Open the application in your web browser and start chatting with GPT models!
|
38 |
+
|
39 |
+
## Contributing
|
40 |
+
|
41 |
+
Contributions are welcome! If you'd like to contribute to the project, please follow these steps:
|
42 |
+
|
43 |
+
1. Fork the repository.
|
44 |
+
2. Create a new branch (`git checkout -b feature/new-feature`).
|
45 |
+
3. Make your changes and commit them (`git commit -am 'Add new feature'`).
|
46 |
+
4. Push to the branch (`git push origin feature/new-feature`).
|
47 |
+
5. Create a new Pull Request.
|
48 |
+
|
49 |
+
## License
|
50 |
+
|
51 |
+
This project is licensed under the MIT License - see the [LICENSE](../Chatbot/LICENSE) file for details.
|
52 |
+
|
53 |
+
## Acknowledgements
|
54 |
+
|
55 |
+
- This project was inspired by the capabilities of GPT models and the desire to create an interactive chat exploration tool.
|
56 |
+
- Special thanks to the Streamlit team for providing a powerful framework for building interactive web applications.
|
requirements.txt
ADDED
Binary file (226 Bytes). View file
|
|
style.css
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
section[data-testid="stSidebar"] div.stButton button {
|
2 |
+
border: none;
|
3 |
+
color: white;
|
4 |
+
padding: auto; /* Adjust padding */
|
5 |
+
text-align: center;
|
6 |
+
text-decoration: none;
|
7 |
+
display: inline-block;
|
8 |
+
font-size: 14px;
|
9 |
+
margin: -2px -2px;
|
10 |
+
transition-duration: 0.4s;
|
11 |
+
cursor: pointer;
|
12 |
+
border-radius: 10px;
|
13 |
+
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.5);
|
14 |
+
min-width: 200px; /* Set minimum width */
|
15 |
+
height: auto;
|
16 |
+
white-space: normal; /* Allow long text to wrap */
|
17 |
+
word-wrap: break-word; /* Allow long text to wrap */
|
18 |
+
}
|
19 |
+
|
20 |
+
section[data-testid="stSidebar"] div.stButton button:hover {
|
21 |
+
background-color: black; /* Darker green on hover */
|
22 |
+
}
|