Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,7 +44,27 @@ if st.button('Record audio'):
|
|
44 |
else:
|
45 |
st.error("API key is required to interact with GPT.")
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
# Download conversation button
|
48 |
-
st.download_button(
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
44 |
else:
|
45 |
st.error("API key is required to interact with GPT.")
|
46 |
|
47 |
+
# # Download conversation button
|
48 |
+
# st.download_button(label="Download conversation",
|
49 |
+
# data=pd.DataFrame(st.session_state['messages']).to_csv(index=False).encode('utf-8'),
|
50 |
+
# file_name=output_conversation_filename)
|
51 |
+
|
52 |
+
# Function to generate conversation as plain text
|
53 |
+
def generate_conversation_text(messages):
|
54 |
+
conversation_text = ""
|
55 |
+
for message in messages:
|
56 |
+
if message["role"] == "user":
|
57 |
+
conversation_text += f"Me: {message['content']}\n"
|
58 |
+
elif message["role"] == "assistant":
|
59 |
+
conversation_text += f"GPT: {message['content']}\n"
|
60 |
+
elif message["role"] == "system":
|
61 |
+
conversation_text += f"System: {message['content']}\n"
|
62 |
+
return conversation_text
|
63 |
+
|
64 |
# Download conversation button
|
65 |
+
st.download_button(
|
66 |
+
label="Download conversation",
|
67 |
+
data=generate_conversation_text(st.session_state['messages']).encode('utf-8'),
|
68 |
+
file_name=output_conversation_filename,
|
69 |
+
mime="text/plain"
|
70 |
+
)
|