Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,16 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import json
|
|
|
|
| 4 |
|
| 5 |
# Constants
|
| 6 |
SPACE_URL = "https://abanm-dubs.hf.space/api/generate"
|
| 7 |
API_KEY = "s3cr3t_k3y" # Replace with your actual API key
|
| 8 |
EOS_TOKEN = "<|end|>"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Streamlit Configurations (must come first)
|
| 11 |
st.set_page_config(page_title="๐ถ DUBSChat", layout="wide")
|
|
@@ -14,8 +19,30 @@ st.set_page_config(page_title="๐ถ DUBSChat", layout="wide")
|
|
| 14 |
with st.sidebar:
|
| 15 |
dubs_key = st.text_input("Enter Dubs Key", key="chatbot_api_key", type="password")
|
| 16 |
st.markdown("### Dubs Recall")
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
st.session_state["messages"] = [
|
| 20 |
{"role": "system", "content": "You are DUBS, a helpful assistant capable of conversing in a friendly and knowledgeable way."},
|
| 21 |
{"role": "assistant", "content": "Hello! How can I assist you today?"}
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
# Constants
|
| 7 |
SPACE_URL = "https://abanm-dubs.hf.space/api/generate"
|
| 8 |
API_KEY = "s3cr3t_k3y" # Replace with your actual API key
|
| 9 |
EOS_TOKEN = "<|end|>"
|
| 10 |
+
CHAT_HISTORY_DIR = "chat_histories" # Directory to save chat histories
|
| 11 |
+
|
| 12 |
+
# Ensure the directory exists
|
| 13 |
+
os.makedirs(CHAT_HISTORY_DIR, exist_ok=True)
|
| 14 |
|
| 15 |
# Streamlit Configurations (must come first)
|
| 16 |
st.set_page_config(page_title="๐ถ DUBSChat", layout="wide")
|
|
|
|
| 19 |
with st.sidebar:
|
| 20 |
dubs_key = st.text_input("Enter Dubs Key", key="chatbot_api_key", type="password")
|
| 21 |
st.markdown("### Dubs Recall")
|
| 22 |
+
|
| 23 |
+
# Save chat history
|
| 24 |
+
if st.button("๐พ Save Chat"):
|
| 25 |
+
if "messages" in st.session_state:
|
| 26 |
+
file_name = st.text_input("Enter filename to save chat:", "chat_history.json")
|
| 27 |
+
if file_name:
|
| 28 |
+
file_path = os.path.join(CHAT_HISTORY_DIR, file_name)
|
| 29 |
+
with open(file_path, "w") as f:
|
| 30 |
+
json.dump(st.session_state["messages"], f)
|
| 31 |
+
st.success(f"Chat saved as {file_name}!")
|
| 32 |
+
|
| 33 |
+
# Load chat history
|
| 34 |
+
file_to_load = st.selectbox("Select a chat to load:", os.listdir(CHAT_HISTORY_DIR))
|
| 35 |
+
if st.button("๐ Load Chat"):
|
| 36 |
+
file_path = os.path.join(CHAT_HISTORY_DIR, file_to_load)
|
| 37 |
+
if os.path.exists(file_path):
|
| 38 |
+
with open(file_path, "r") as f:
|
| 39 |
+
st.session_state["messages"] = json.load(f)
|
| 40 |
+
st.success(f"Loaded chat from {file_to_load}!")
|
| 41 |
+
else:
|
| 42 |
+
st.error(f"File {file_to_load} does not exist.")
|
| 43 |
+
|
| 44 |
+
# Reset chat
|
| 45 |
+
if st.button("๐ Reset Chat"):
|
| 46 |
st.session_state["messages"] = [
|
| 47 |
{"role": "system", "content": "You are DUBS, a helpful assistant capable of conversing in a friendly and knowledgeable way."},
|
| 48 |
{"role": "assistant", "content": "Hello! How can I assist you today?"}
|