|
1 | 1 | import streamlit as st |
2 | | -from g4f.client import Client |
3 | | -import sqlite3 |
4 | | -import google.generativeai as genai |
5 | | -import csv |
6 | | -import os |
7 | | -# import pyttsx3 |
8 | | -import pyperclip |
9 | 2 |
|
10 | | - |
11 | | -st.set_page_config(page_title="DarkGPT", |
12 | | - page_icon="🤖", |
13 | | - layout="wide", |
14 | | - initial_sidebar_state="expanded" |
| 3 | +# Set page configuration |
| 4 | +st.set_page_config( |
| 5 | + page_title="DarkGPT", |
| 6 | + page_icon="🤖", |
| 7 | + layout="wide", |
| 8 | + initial_sidebar_state="expanded" |
15 | 9 | ) |
16 | | -def local_css(file_name): |
17 | | - with open(file_name) as f: |
18 | | - st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True) |
19 | | - |
20 | | - |
21 | | -local_css("style.css") |
22 | | - |
23 | | -# Create a connection to the database |
24 | | -conn = sqlite3.connect('chat_history.db') |
25 | | -c = conn.cursor() |
26 | | - |
27 | | -# Create table if not exists |
28 | | -try: |
29 | | - c.execute('''CREATE TABLE IF NOT EXISTS chat_history |
30 | | - (conversation_id INTEGER, role TEXT, content TEXT)''') |
31 | | - conn.commit() |
32 | | -except Exception as e: |
33 | | - st.error(f"An error occurred: {e}") |
34 | | - |
35 | | -# Streamlit app |
36 | | -def main(): |
37 | | - try: |
38 | | - if "chat_history" not in st.session_state: |
39 | | - st.session_state.chat_history = [] |
40 | | - |
41 | | - if "conversation_id" not in st.session_state: |
42 | | - st.session_state.conversation_id = 1 |
43 | | - |
44 | | - models = { |
45 | | - "🚀 Airoboros 70B": "airoboros-70b", |
46 | | - "👑 Gemini 1.0": "gemini-1.0-pro", |
47 | | - "🧨 Gemini 1.0 Pro ": "gemini-1.0-pro-001", |
48 | | - "⚡ Gemini 1.0 pro latest": "gemini-1.0-pro-latest", |
49 | | - "🔮 Gemini Pro": "gemini-pro" |
50 | | - } |
51 | | - |
52 | | - columns = st.columns(3) # Split the layout into three columns |
53 | | - with columns[0]: |
54 | | - st.header("DarkGPT") |
55 | | - |
56 | | - with columns[2]: |
57 | | - |
58 | | - selected_model_display_name = st.selectbox("Select Model", list(models.keys()), index=0) |
59 | | - selected_model = models[selected_model_display_name] |
60 | | - |
61 | | - with columns[1]: |
62 | | - pass |
63 | | - # if st.button("summarize"): |
64 | | - # st.switch_page('pages/summarize.py') |
65 | | - |
66 | | - # Sidebar (left side) - New chat button |
67 | | - if st.sidebar.button("✨ New Chat", key="new_chat_button"): |
68 | | - st.session_state.chat_history.clear() |
69 | | - st.session_state.conversation_id += 1 |
70 | | - |
71 | | - # Sidebar (left side) - Display saved chat |
72 | | - st.sidebar.write("Chat History") |
73 | | - c.execute("SELECT DISTINCT conversation_id FROM chat_history") |
74 | | - conversations = c.fetchall() |
75 | | - for conv_id in reversed(conversations): |
76 | | - c.execute("SELECT content FROM chat_history WHERE conversation_id=? AND role='bot' LIMIT 1", |
77 | | - (conv_id[0],)) |
78 | | - first_bot_response = c.fetchone() |
79 | | - if first_bot_response: |
80 | | - if st.sidebar.button(" ".join(first_bot_response[0].split()[0:5])): |
81 | | - display_conversation(conv_id[0]) |
82 | | - |
83 | | - # Sidebar (left side) - Clear Chat History button |
84 | | - if st.sidebar.button("Clear Chat History ✖️"): |
85 | | - st.session_state.chat_history.clear() |
86 | | - c.execute("DELETE FROM chat_history") |
87 | | - conn.commit() |
88 | | - |
89 | | - # Main content area (center) |
90 | | - st.markdown("---") |
91 | | - |
92 | | - user_input = st.chat_input("Ask Anything ...") |
93 | | - |
94 | | - if user_input: |
95 | | - if selected_model == "airoboros-70b": |
96 | | - try: |
97 | | - client = Client() |
98 | | - response = client.chat.completions.create( |
99 | | - model=models[selected_model_display_name], |
100 | | - messages=[{"role": "user", "content": user_input}], |
101 | | - ) |
102 | | - bot_response = response.choices[0].message.content |
103 | | - |
104 | | - st.session_state.chat_history.append({"role": "user", "content": user_input}) |
105 | | - st.session_state.chat_history.append({"role": "bot", "content": bot_response}) |
106 | | - |
107 | | - # Store chat in the database |
108 | | - for chat in st.session_state.chat_history: |
109 | | - c.execute("INSERT INTO chat_history VALUES (?, ?, ?)", |
110 | | - (st.session_state.conversation_id, chat["role"], chat["content"])) |
111 | | - conn.commit() |
112 | | - |
113 | | - # Display chat history |
114 | | - for index, chat in enumerate(st.session_state.chat_history): |
115 | | - with st.chat_message(chat["role"]): |
116 | | - if chat["role"] == "user": |
117 | | - st.markdown(chat["content"]) |
118 | | - elif chat["role"] == "bot": |
119 | | - st.markdown(chat["content"]) |
120 | | - |
121 | | - except Exception as e: |
122 | | - st.error(f"An error occurred: {e}") |
123 | | - |
124 | | - else: |
125 | | - try: |
126 | | - # GEMINI Replace with your Gemini Api key |
127 | | - GOOGLE_API_KEY = os.getenv('gemini-api') |
128 | | - genai.configure(api_key=GOOGLE_API_KEY) |
129 | | - model = genai.GenerativeModel(selected_model) |
130 | | - prompt = user_input |
131 | | - response = model.generate_content(prompt) |
132 | | - bot_response = response.candidates[0].content.parts[0].text |
133 | | - |
134 | | - st.session_state.chat_history.append({"role": "user", "content": user_input}) |
135 | | - st.session_state.chat_history.append({"role": "bot", "content": bot_response}) |
136 | | - |
137 | | - # Store chat in the database |
138 | | - for chat in st.session_state.chat_history: |
139 | | - c.execute("INSERT INTO chat_history VALUES (?, ?, ?)", |
140 | | - (st.session_state.conversation_id, chat["role"], chat["content"])) |
141 | | - conn.commit() |
142 | | - |
143 | | - for index, chat in enumerate(st.session_state.chat_history): |
144 | | - with st.chat_message(chat["role"]): |
145 | | - if chat["role"] == "user": |
146 | | - st.markdown(chat["content"]) |
147 | | - elif chat["role"] == "bot": |
148 | | - st.markdown(chat["content"]) |
149 | | - |
150 | | - except Exception as e: |
151 | | - st.error(f"An error occurred: {e}") |
152 | | - |
153 | | - # export_to_csv(st.session_state.chat_history) |
154 | | - |
155 | | - |
156 | | - except Exception as e: |
157 | | - st.error(f"An error occurred: {e}") |
158 | | - |
159 | | -# def export_to_csv(chat_history): |
160 | | -# filename = "chat_history.csv" |
161 | | -# latest_conversation = chat_history[-2:] # Get only the latest conversation |
162 | | -# with open(filename, "a+", newline="") as csvfile: |
163 | | -# fieldnames = ["User Input", "Bot Response"] |
164 | | -# writer = csv.DictWriter(csvfile, fieldnames=fieldnames) |
165 | | -# if csvfile.tell() == 0: # Check if the file is empty |
166 | | -# writer.writeheader() # Write header if file is empty |
167 | | -# if len(latest_conversation) == 2: # Check if the latest conversation is complete |
168 | | -# writer.writerow({"User Input": latest_conversation[0]["content"], "Bot Response": latest_conversation[1]["content"]}) |
169 | 10 |
|
170 | | -def display_conversation(conversation_id): |
171 | | - c.execute("SELECT * FROM chat_history WHERE conversation_id=?", (conversation_id,)) |
172 | | - chats = c.fetchall() |
173 | | - st.markdown(f"### Conversation") |
174 | | - for chat in chats: |
175 | | - st.markdown(f"{chat[1]}") |
176 | | - st.markdown(f"{chat[2]}") |
| 11 | +def display_homepage(): |
| 12 | + st.markdown("<h1 style='text-align: center; color: white; font-size: 36px;'>Welcome to DarkGPT! 🧨</h1>", unsafe_allow_html=True) |
| 13 | + st.markdown("<h3 style='text-align: center; font-size: 56px;'>🤖</h3>", unsafe_allow_html=True) |
| 14 | + st.markdown("<h3 style='text-align: center; color: grey; font-size: 20px;'>DarkGPT: Your AI text assistant for quick summarization and analysis. Summarize text, analyze complexity, and get insights instantly!</h3>", unsafe_allow_html=True) |
| 15 | + |
| 16 | + st.markdown('---') |
| 17 | + |
| 18 | + st.markdown("<h3 style='text-align: left; color:#F63366; font-size: 24px;'><b>What is DarkGPT?</b></h3>", unsafe_allow_html=True) |
| 19 | + st.markdown(""" |
| 20 | + DarkGPT is a versatile AI-powered text assistant designed to enhance your reading and writing experience. |
| 21 | + Leveraging advanced natural language processing models, DarkGPT provides two main functionalities: |
| 22 | + text summarization and text analysis. Whether you need to quickly understand the essence of a lengthy article or |
| 23 | + dive deep into the complexity of a text, DarkGPT is here to help. |
| 24 | + """) |
| 25 | + |
| 26 | + st.markdown("<h3 style='text-align: left; color:#F63366; font-size: 24px;'><b>Features</b></h3>", unsafe_allow_html=True) |
| 27 | + |
| 28 | + st.markdown("### 🤖 DarkGPT - AI-Powered Chatbot:\n" |
| 29 | + "DarkGPT is an advanced AI-powered chatbot designed to simulate human-like conversations.\n" |
| 30 | + "Using state-of-the-art natural language processing models, DarkGPT can understand and generate\n" |
| 31 | + "responses based on user input, making it ideal for various applications such as customer support,\n" |
| 32 | + "virtual assistants, and interactive content generation.\n\n" |
| 33 | + "DarkGPT supports multiple AI models, each tailored for different tasks and levels of complexity.\n" |
| 34 | + "Users can select from a range of models, including those optimized for general chat, technical queries,\n" |
| 35 | + "creative writing, and more, providing flexibility and customization to suit specific needs.\n\n" |
| 36 | + "**Key Features:**\n" |
| 37 | + "- **AI Models:** Utilizes models like Airoboros 70B and Gemini Pro for robust conversation handling.\n" |
| 38 | + "- **Natural Language Processing:** Processes user input to generate contextually relevant responses.\n" |
| 39 | + "- **Chat History:** Stores and retrieves chat history to maintain continuity across sessions.\n" |
| 40 | + "- **Customization:** Offers options to fine-tune responses and personalize user interaction.\n\n" |
| 41 | + "Explore DarkGPT's capabilities and start conversing today!", unsafe_allow_html=True) |
| 42 | + |
| 43 | + st.markdown("### 🔍 Summarization Page:\n" |
| 44 | + "- **Input Options:** Users can input text directly or upload a text file for summarization.\n" |
| 45 | + "- **Example Text:** An example text is provided to help users get started quickly.\n" |
| 46 | + "- **Summarize Button:** Click the 'Summarize' button to generate a summary using the BART model.\n" |
| 47 | + "- **Error Handling:** Error messages are displayed if the input text length requirements are not met.", unsafe_allow_html=True) |
| 48 | + |
| 49 | + st.markdown("### 📊 Analysis Page:\n" |
| 50 | + "- **Input Options:** Users can input text directly or upload a text file for analysis.\n" |
| 51 | + "- **Example Text:** An example text is provided to help users get started quickly.\n" |
| 52 | + "- **Analyze Button:** Click the 'Analyze' button to generate various metrics such as reading time, text complexity, lexical richness, and number of sentences.\n" |
| 53 | + "- **Error Handling:** Error messages are displayed if the input text length requirements are not met.", unsafe_allow_html=True) |
| 54 | + |
| 55 | + footer = ''' |
| 56 | + <footer style="text-align: center; margin-top: 50px; font-family: Arial, sans-serif; color: #555;"> |
| 57 | + <p>Developed by DarkCoder</p> |
| 58 | + <p> |
| 59 | + <a href="https://github.com/codewithdark-git" target="_blank" style="text-decoration: none; color: #007bff; margin-right: 10px;">GitHub</a> |
| 60 | + | <a href="https://www.linkedin.com/in/codewithdark/" target="_blank" style="text-decoration: none; color: #007bff; margin-right: 10px;">Linkedin</a> |
| 61 | + | <a href="https://www.facebook.com/codewithdark.fb/" target="_blank" style="text-decoration: none; color: #007bff;">Facebook</a> |
| 62 | + </p> |
| 63 | + </footer> |
| 64 | + ''' |
| 65 | + |
| 66 | + # Display the footer |
| 67 | + st.markdown(footer, unsafe_allow_html=True) |
177 | 68 |
|
178 | 69 | if __name__ == "__main__": |
179 | | - main() |
| 70 | + display_homepage() |
0 commit comments