Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import json
|
|
4 |
import os
|
5 |
from datetime import datetime
|
6 |
|
7 |
-
|
8 |
API_ENDPOINT = os.getenv("API_ENDPOINT", "none")
|
9 |
API_TOKEN = os.getenv("API_TOKEN")
|
10 |
|
@@ -69,6 +69,10 @@ def update_history_display(stored_history):
|
|
69 |
html += f"<script>localStorage.setItem('chat_history', JSON.stringify({json.dumps(stored_history)}))</script>"
|
70 |
return html
|
71 |
|
|
|
|
|
|
|
|
|
72 |
# Modern CSS for a clean UI
|
73 |
custom_css = """
|
74 |
body { background-color: #1a1a1a; color: #ffffff; font-family: 'Arial', sans-serif; }
|
@@ -82,7 +86,7 @@ button:hover { background-color: #404040; }
|
|
82 |
"""
|
83 |
|
84 |
# Build the Gradio app
|
85 |
-
with gr.Blocks(css=custom_css, title="
|
86 |
with gr.Row():
|
87 |
# Sidebar for history
|
88 |
with gr.Column(scale=1, min_width=300, elem_id="sidebar"):
|
@@ -92,7 +96,7 @@ with gr.Blocks(css=custom_css, title="Modern AI Chatbot") as demo:
|
|
92 |
|
93 |
# Main chat area
|
94 |
with gr.Column(scale=3):
|
95 |
-
chatbot = gr.Chatbot(elem_id="chatbot"
|
96 |
with gr.Row():
|
97 |
message = gr.Textbox(placeholder="Type your message...", show_label=False, container=False)
|
98 |
submit_btn = gr.Button("Send", size="sm")
|
@@ -133,19 +137,21 @@ with gr.Blocks(css=custom_css, title="Modern AI Chatbot") as demo:
|
|
133 |
history_display
|
134 |
)
|
135 |
|
136 |
-
# Load initial history
|
|
|
|
|
137 |
demo.load(
|
138 |
-
|
139 |
-
None,
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
).then(
|
146 |
update_history_display,
|
147 |
-
history_state,
|
148 |
-
history_display
|
149 |
)
|
150 |
|
151 |
demo.launch()
|
|
|
4 |
import os
|
5 |
from datetime import datetime
|
6 |
|
7 |
+
|
8 |
API_ENDPOINT = os.getenv("API_ENDPOINT", "none")
|
9 |
API_TOKEN = os.getenv("API_TOKEN")
|
10 |
|
|
|
69 |
html += f"<script>localStorage.setItem('chat_history', JSON.stringify({json.dumps(stored_history)}))</script>"
|
70 |
return html
|
71 |
|
72 |
+
# Function to load history from JavaScript
|
73 |
+
def load_history_from_js():
|
74 |
+
return gr.Var(value=[], js="() => { const history = localStorage.getItem('chat_history'); return history ? JSON.parse(history) : []; }")
|
75 |
+
|
76 |
# Modern CSS for a clean UI
|
77 |
custom_css = """
|
78 |
body { background-color: #1a1a1a; color: #ffffff; font-family: 'Arial', sans-serif; }
|
|
|
86 |
"""
|
87 |
|
88 |
# Build the Gradio app
|
89 |
+
with gr.Blocks(css=custom_css, title="Reka Flash 3 Demo") as demo:
|
90 |
with gr.Row():
|
91 |
# Sidebar for history
|
92 |
with gr.Column(scale=1, min_width=300, elem_id="sidebar"):
|
|
|
96 |
|
97 |
# Main chat area
|
98 |
with gr.Column(scale=3):
|
99 |
+
chatbot = gr.Chatbot(elem_id="chatbot")
|
100 |
with gr.Row():
|
101 |
message = gr.Textbox(placeholder="Type your message...", show_label=False, container=False)
|
102 |
submit_btn = gr.Button("Send", size="sm")
|
|
|
137 |
history_display
|
138 |
)
|
139 |
|
140 |
+
# Load initial history with JavaScript
|
141 |
+
history_from_js = gr.JSON(visible=False)
|
142 |
+
|
143 |
demo.load(
|
144 |
+
load_history_from_js,
|
145 |
+
inputs=None,
|
146 |
+
outputs=history_from_js
|
147 |
+
).then(
|
148 |
+
lambda x: x,
|
149 |
+
inputs=history_from_js,
|
150 |
+
outputs=history_state
|
151 |
).then(
|
152 |
update_history_display,
|
153 |
+
inputs=history_state,
|
154 |
+
outputs=history_display
|
155 |
)
|
156 |
|
157 |
demo.launch()
|