Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -91,26 +91,163 @@ def process_message(user_input, chat_history, token_history):
|
|
91 |
def clear_history():
|
92 |
return [], []
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
def clear_history():
|
92 |
return [], []
|
93 |
|
94 |
+
# Custom CSS for styling
|
95 |
+
custom_css = """
|
96 |
+
body {
|
97 |
+
background: linear-gradient(to bottom, #1a1a1a, #2a2a2a);
|
98 |
+
font-family: 'Roboto', sans-serif;
|
99 |
+
color: white;
|
100 |
+
margin: 0;
|
101 |
+
padding: 0;
|
102 |
+
}
|
103 |
+
|
104 |
+
.container {
|
105 |
+
max-width: 800px;
|
106 |
+
margin: 0 auto;
|
107 |
+
padding: 20px;
|
108 |
+
}
|
109 |
+
|
110 |
+
.gr-chatbot {
|
111 |
+
font-size: 16px;
|
112 |
+
border: none;
|
113 |
+
background-color: #1e1e1e;
|
114 |
+
border-radius: 8px;
|
115 |
+
padding: 10px;
|
116 |
+
}
|
117 |
+
|
118 |
+
.gr-chatbot .bubble.user {
|
119 |
+
background-color: #2d2d2d !important;
|
120 |
+
border-radius: 8px;
|
121 |
+
padding: 12px;
|
122 |
+
margin: 8px 0;
|
123 |
+
}
|
124 |
+
|
125 |
+
.gr-chatbot .bubble.assistant {
|
126 |
+
background-color: #3d3d3d !important;
|
127 |
+
border-radius: 8px;
|
128 |
+
padding: 12px;
|
129 |
+
margin: 8px 0;
|
130 |
+
}
|
131 |
+
|
132 |
+
.gr-button {
|
133 |
+
background-color: #4CAF50;
|
134 |
+
color: white;
|
135 |
+
border: none;
|
136 |
+
padding: 12px 24px;
|
137 |
+
font-size: 16px;
|
138 |
+
border-radius: 4px;
|
139 |
+
cursor: pointer;
|
140 |
+
transition: background-color 0.3s;
|
141 |
+
}
|
142 |
+
|
143 |
+
.gr-button:hover {
|
144 |
+
background-color: #45a049;
|
145 |
+
}
|
146 |
+
|
147 |
+
.gr-text-input input {
|
148 |
+
background-color: #2d2d2d;
|
149 |
+
color: white;
|
150 |
+
border: 1px solid #4CAF50;
|
151 |
+
border-radius: 4px;
|
152 |
+
padding: 10px;
|
153 |
+
font-size: 16px;
|
154 |
+
}
|
155 |
+
|
156 |
+
.header {
|
157 |
+
display: flex;
|
158 |
+
align-items: center;
|
159 |
+
justify-content: center;
|
160 |
+
padding: 20px 0;
|
161 |
+
text-align: center;
|
162 |
+
}
|
163 |
+
|
164 |
+
.header img {
|
165 |
+
width: 60px;
|
166 |
+
height: 60px;
|
167 |
+
margin-right: 15px;
|
168 |
+
}
|
169 |
+
|
170 |
+
.footer {
|
171 |
+
text-align: center;
|
172 |
+
padding: 20px;
|
173 |
+
font-size: 14px;
|
174 |
+
color: #ccc;
|
175 |
+
margin-top: 30px;
|
176 |
+
}
|
177 |
+
|
178 |
+
.title {
|
179 |
+
font-size: 28px;
|
180 |
+
font-weight: bold;
|
181 |
+
color: #ffffff;
|
182 |
+
margin: 0;
|
183 |
+
}
|
184 |
+
|
185 |
+
.subtitle {
|
186 |
+
font-size: 16px;
|
187 |
+
color: #cccccc;
|
188 |
+
margin: 5px 0 0 0;
|
189 |
+
}
|
190 |
+
"""
|
191 |
+
|
192 |
+
with gr.Blocks(
|
193 |
+
theme="dark",
|
194 |
+
css=custom_css
|
195 |
+
) as demo:
|
196 |
+
with gr.Column(elem_classes=["container"]):
|
197 |
+
# Header
|
198 |
+
with gr.Row(elem_classes=["header"]):
|
199 |
+
gr.Image(
|
200 |
+
value="https://huggingface.co/TimurHromek/HROM-V1/resolve/main/hrom_icon.png",
|
201 |
+
interactive=False,
|
202 |
+
width=60,
|
203 |
+
height=60,
|
204 |
+
show_label=False
|
205 |
+
)
|
206 |
+
with gr.Column():
|
207 |
+
gr.Markdown("<div class='title'>HROM-V1 Chatbot</div>")
|
208 |
+
gr.Markdown("<div class='subtitle'>Powered by Gradio and Hugging Face</div>")
|
209 |
+
|
210 |
+
# Chatbot
|
211 |
+
chatbot = gr.Chatbot(
|
212 |
+
height=500,
|
213 |
+
avatar_images=[
|
214 |
+
("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/test_image.png", "user"),
|
215 |
+
("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/favicon.png", "assistant")
|
216 |
+
],
|
217 |
+
bubble_full_width=False
|
218 |
+
)
|
219 |
+
|
220 |
+
# Input
|
221 |
+
msg = gr.Textbox(
|
222 |
+
label="Your Message",
|
223 |
+
placeholder="Type your message here...",
|
224 |
+
lines=2
|
225 |
+
)
|
226 |
+
|
227 |
+
# Buttons
|
228 |
+
clear_btn = gr.Button("Clear Chat History")
|
229 |
+
|
230 |
+
# State
|
231 |
+
token_state = gr.State([])
|
232 |
+
|
233 |
+
# Event handlers
|
234 |
+
msg.submit(
|
235 |
+
process_message,
|
236 |
+
[msg, chatbot, token_state],
|
237 |
+
[chatbot, token_state],
|
238 |
+
queue=False
|
239 |
+
).then(
|
240 |
+
lambda: "", None, msg
|
241 |
+
)
|
242 |
+
|
243 |
+
clear_btn.click(
|
244 |
+
clear_history,
|
245 |
+
outputs=[chatbot, token_state],
|
246 |
+
queue=False
|
247 |
+
)
|
248 |
+
|
249 |
+
# Footer
|
250 |
+
gr.Markdown("<div class='footer'>© 2025 HROM-V1 | Model by Timur Hromek | Assisted by Elapt1c</div>")
|
251 |
+
|
252 |
+
if __name__ == "__main__":
|
253 |
+
demo.launch()
|