Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
from openai import OpenAI
|
|
@@ -58,23 +57,6 @@ def chat(message, history, response_id):
|
|
| 58 |
error_message = f"Error: {str(e)}"
|
| 59 |
return history + [[message, error_message]], None
|
| 60 |
|
| 61 |
-
def export_chat():
|
| 62 |
-
"""Export conversation history as downloadable JSON"""
|
| 63 |
-
global conversation_history
|
| 64 |
-
|
| 65 |
-
if not conversation_history:
|
| 66 |
-
return None, "No conversation to export"
|
| 67 |
-
|
| 68 |
-
# Create filename with timestamp
|
| 69 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 70 |
-
filename = f"chat_export_{timestamp}.json"
|
| 71 |
-
|
| 72 |
-
# Create JSON content
|
| 73 |
-
json_content = json.dumps(conversation_history, indent=2)
|
| 74 |
-
|
| 75 |
-
# Return file for download
|
| 76 |
-
return (filename, json_content), "Chat exported successfully. Download should start automatically."
|
| 77 |
-
|
| 78 |
def clear_chat(history):
|
| 79 |
"""Clear the chat history"""
|
| 80 |
global conversation_history
|
|
@@ -115,12 +97,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 115 |
|
| 116 |
with gr.Row():
|
| 117 |
clear_btn = gr.Button("Clear Chat")
|
| 118 |
-
export_btn = gr.Button("Export Chat (JSON)")
|
| 119 |
|
| 120 |
-
# File download component and status message
|
| 121 |
-
file_output = gr.File(label="Download Chat")
|
| 122 |
-
export_message = gr.Textbox(label="Export Status")
|
| 123 |
-
|
| 124 |
# Set up event handlers
|
| 125 |
api_submit_btn.click(
|
| 126 |
save_api_key,
|
|
@@ -154,11 +131,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 154 |
outputs=[chatbot, response_id]
|
| 155 |
)
|
| 156 |
|
| 157 |
-
export_btn.click(
|
| 158 |
-
export_chat,
|
| 159 |
-
outputs=[file_output, export_message]
|
| 160 |
-
)
|
| 161 |
-
|
| 162 |
# Footer
|
| 163 |
gr.HTML("""
|
| 164 |
<div style="text-align: center; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #ddd">
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
|
|
|
| 57 |
error_message = f"Error: {str(e)}"
|
| 58 |
return history + [[message, error_message]], None
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
def clear_chat(history):
|
| 61 |
"""Clear the chat history"""
|
| 62 |
global conversation_history
|
|
|
|
| 97 |
|
| 98 |
with gr.Row():
|
| 99 |
clear_btn = gr.Button("Clear Chat")
|
|
|
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
# Set up event handlers
|
| 102 |
api_submit_btn.click(
|
| 103 |
save_api_key,
|
|
|
|
| 131 |
outputs=[chatbot, response_id]
|
| 132 |
)
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
# Footer
|
| 135 |
gr.HTML("""
|
| 136 |
<div style="text-align: center; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #ddd">
|