Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -81,16 +81,19 @@ for message in st.session_state.messages:
|
|
81 |
with st.chat_message(message["role"], avatar=avatar):
|
82 |
st.markdown(message["content"])
|
83 |
|
84 |
-
# Function to save prompt
|
85 |
def save_prompt(prompt):
|
86 |
-
|
87 |
-
|
88 |
-
st.session_state.saved_prompts.append(prompt)
|
89 |
|
90 |
-
# Function to delete prompt
|
91 |
def delete_prompt(prompt_index):
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
94 |
|
95 |
|
96 |
def generate_chat_responses(chat_completion) -> Generator[str, None, None]:
|
@@ -105,6 +108,9 @@ if prompt := st.chat_input("Enter your prompt here..."):
|
|
105 |
with st.chat_message("user", avatar="❓"):
|
106 |
st.markdown(prompt)
|
107 |
|
|
|
|
|
|
|
108 |
# Fetch response from Groq API
|
109 |
try:
|
110 |
chat_completion = client.chat.completions.create(
|
@@ -138,9 +144,11 @@ if prompt := st.chat_input("Enter your prompt here..."):
|
|
138 |
|
139 |
# Collapsible section for prompt management
|
140 |
with st.expander("Prompt Management", expanded=False):
|
141 |
-
if "saved_prompts"
|
142 |
-
|
|
|
|
|
143 |
delete_button = st.button("Delete", key=f"delete_{i}")
|
144 |
-
st.write(f"{i + 1}. {prompt}")
|
145 |
if delete_button:
|
146 |
delete_prompt(i)
|
|
|
81 |
with st.chat_message(message["role"], avatar=avatar):
|
82 |
st.markdown(message["content"])
|
83 |
|
84 |
+
# Function to save prompt to a file
|
85 |
def save_prompt(prompt):
|
86 |
+
with open("saved_prompts.txt", "a") as file:
|
87 |
+
file.write(prompt + "\n")
|
|
|
88 |
|
89 |
+
# Function to delete prompt from file
|
90 |
def delete_prompt(prompt_index):
|
91 |
+
with open("saved_prompts.txt", "r") as file:
|
92 |
+
prompts = file.readlines()
|
93 |
+
with open("saved_prompts.txt", "w") as file:
|
94 |
+
for i, p in enumerate(prompts):
|
95 |
+
if i != prompt_index:
|
96 |
+
file.write(p)
|
97 |
|
98 |
|
99 |
def generate_chat_responses(chat_completion) -> Generator[str, None, None]:
|
|
|
108 |
with st.chat_message("user", avatar="❓"):
|
109 |
st.markdown(prompt)
|
110 |
|
111 |
+
if st.button("Save"):
|
112 |
+
save_prompt(prompt)
|
113 |
+
|
114 |
# Fetch response from Groq API
|
115 |
try:
|
116 |
chat_completion = client.chat.completions.create(
|
|
|
144 |
|
145 |
# Collapsible section for prompt management
|
146 |
with st.expander("Prompt Management", expanded=False):
|
147 |
+
if os.path.exists("saved_prompts.txt"):
|
148 |
+
with open("saved_prompts.txt", "r") as file:
|
149 |
+
saved_prompts = file.readlines()
|
150 |
+
for i, prompt in enumerate(saved_prompts):
|
151 |
delete_button = st.button("Delete", key=f"delete_{i}")
|
152 |
+
st.write(f"{i + 1}. {prompt.strip()}")
|
153 |
if delete_button:
|
154 |
delete_prompt(i)
|