Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import torch
|
|
3 |
import importlib.util
|
4 |
from tokenizers import Tokenizer
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
-
import os
|
7 |
|
8 |
# Download and import model components from HF Hub
|
9 |
model_repo = "TimurHromek/HROM-V1"
|
@@ -105,18 +104,102 @@ def process_message(user_input, chat_history, token_history, temperature, max_co
|
|
105 |
def clear_history():
|
106 |
return [], []
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
with gr.Row():
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
msg.submit(
|
122 |
process_message,
|
@@ -127,7 +210,6 @@ with gr.Blocks() as demo:
|
|
127 |
lambda: "", None, msg
|
128 |
)
|
129 |
|
130 |
-
clear_btn = gr.Button("Clear Chat History")
|
131 |
clear_btn.click(
|
132 |
clear_history,
|
133 |
outputs=[chatbot, token_state],
|
|
|
3 |
import importlib.util
|
4 |
from tokenizers import Tokenizer
|
5 |
from huggingface_hub import hf_hub_download
|
|
|
6 |
|
7 |
# Download and import model components from HF Hub
|
8 |
model_repo = "TimurHromek/HROM-V1"
|
|
|
104 |
def clear_history():
|
105 |
return [], []
|
106 |
|
107 |
+
css = """
|
108 |
+
:root {
|
109 |
+
--background: white;
|
110 |
+
--text: black;
|
111 |
+
--border: #e0e0e0;
|
112 |
+
--button-bg: #f0f0f0;
|
113 |
+
--button-hover: #e0e0e0;
|
114 |
+
--chatbot-bg: #f8f8f8;
|
115 |
+
}
|
116 |
+
|
117 |
+
.dark {
|
118 |
+
--background: #1a1a1a;
|
119 |
+
--text: white;
|
120 |
+
--border: #404040;
|
121 |
+
--button-bg: #404040;
|
122 |
+
--button-hover: #505050;
|
123 |
+
--chatbot-bg: #262626;
|
124 |
+
}
|
125 |
+
|
126 |
+
body {
|
127 |
+
background: var(--background) !important;
|
128 |
+
color: var(--text) !important;
|
129 |
+
}
|
130 |
+
|
131 |
+
.gr-box {
|
132 |
+
border-color: var(--border) !important;
|
133 |
+
background: var(--background) !important;
|
134 |
+
}
|
135 |
+
|
136 |
+
.gr-button {
|
137 |
+
background: var(--button-bg) !important;
|
138 |
+
color: var(--text) !important;
|
139 |
+
border-color: var(--border) !important;
|
140 |
+
}
|
141 |
+
|
142 |
+
.gr-button:hover {
|
143 |
+
background: var(--button-hover) !important;
|
144 |
+
}
|
145 |
+
|
146 |
+
#chatbot {
|
147 |
+
background: var(--chatbot-bg) !important;
|
148 |
+
border-color: var(--border) !important;
|
149 |
+
}
|
150 |
+
|
151 |
+
.gr-textbox input {
|
152 |
+
color: var(--text) !important;
|
153 |
+
}
|
154 |
+
|
155 |
+
.dark .gr-markdown {
|
156 |
+
color: var(--text) !important;
|
157 |
+
}
|
158 |
+
"""
|
159 |
+
|
160 |
+
with gr.Blocks(css=css, title="HROM-V1.5 Chatbot") as demo:
|
161 |
+
current_theme = gr.Variable("light")
|
162 |
|
163 |
with gr.Row():
|
164 |
+
with gr.Column(scale=3):
|
165 |
+
gr.Markdown("# HROM-V1.5 Chatbot")
|
166 |
+
chatbot = gr.Chatbot(height=500, elem_id="chatbot")
|
167 |
+
msg = gr.Textbox(label="Your Message", placeholder="Type your message...", show_label=False)
|
168 |
+
|
169 |
+
with gr.Column(scale=1, min_width=300):
|
170 |
+
with gr.Accordion("⚙️ Settings", open=False):
|
171 |
+
with gr.Row():
|
172 |
+
theme_btn = gr.Button("🌙 Dark Theme", variant="secondary")
|
173 |
+
with gr.Row():
|
174 |
+
temperature = gr.Slider(0.1, 2.0, value=1.0, step=0.1,
|
175 |
+
label="Temperature (higher = more creative)")
|
176 |
+
with gr.Row():
|
177 |
+
max_context = gr.Slider(100, CONFIG["max_seq_len"] - max_response_length,
|
178 |
+
value=CONFIG["max_seq_len"] - max_response_length, step=1,
|
179 |
+
label="Context Window Size")
|
180 |
+
with gr.Row():
|
181 |
+
clear_btn = gr.Button("Clear Chat History", variant="secondary")
|
182 |
+
|
183 |
+
token_state = gr.State([])
|
184 |
+
|
185 |
+
def toggle_theme(theme):
|
186 |
+
new_theme = "dark" if theme == "light" else "light"
|
187 |
+
btn_text = "🌞 Light Theme" if new_theme == "light" else "🌙 Dark Theme"
|
188 |
+
return (
|
189 |
+
new_theme,
|
190 |
+
gr.Button.update(value=btn_text),
|
191 |
+
gr.HTML.update(value=f"<style>.dark {{display: {'block' if new_theme == 'dark' else 'none'}}}</style>")
|
192 |
+
)
|
193 |
+
|
194 |
+
theme_btn.click(
|
195 |
+
toggle_theme,
|
196 |
+
current_theme,
|
197 |
+
[current_theme, theme_btn],
|
198 |
+
_js="""(theme) => {
|
199 |
+
document.body.classList.toggle('dark');
|
200 |
+
return document.body.classList.contains('dark') ? 'dark' : 'light';
|
201 |
+
}"""
|
202 |
+
)
|
203 |
|
204 |
msg.submit(
|
205 |
process_message,
|
|
|
210 |
lambda: "", None, msg
|
211 |
)
|
212 |
|
|
|
213 |
clear_btn.click(
|
214 |
clear_history,
|
215 |
outputs=[chatbot, token_state],
|