Yordann commited on
Commit
140474f
Β·
verified Β·
1 Parent(s): fde08e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +326 -16
app.py CHANGED
@@ -14,7 +14,7 @@ def generate_response(user_input, top_p, temperature, chat_counter, chatbot, his
14
  print(f"Detected language: {lang}")
15
 
16
  if lang == "bg":
17
- user_input_translated = bg_to_en(user_input)[0]['translation_text']
18
  else:
19
  user_input_translated = user_input
20
 
@@ -28,7 +28,7 @@ def generate_response(user_input, top_p, temperature, chat_counter, chatbot, his
28
  response = generator(prompt, max_length=200, top_p=top_p, temperature=temperature, do_sample=True)[0]["generated_text"]
29
 
30
  if lang == "bg":
31
- response = en_to_bg(response)[0]['translation_text']
32
 
33
  chat_counter += 1
34
  history.append((user_input, response))
@@ -38,26 +38,336 @@ def generate_response(user_input, top_p, temperature, chat_counter, chatbot, his
38
  def reset_textbox():
39
  return gr.update(value='', interactive=False), gr.update(interactive=False)
40
 
41
- with gr.Blocks(theme=gr.themes.Default()) as demo:
42
- gr.Markdown("""
43
- # πŸ›οΈ MasterBrand AI Assistant
44
- Ask me anything about your e-commerce store – in English or Bulgarian.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  """)
46
 
47
- chatbot = gr.Chatbot()
48
- inputs = gr.Textbox(placeholder="What product should I sell?", label="Your question")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  state = gr.State([])
50
  chat_counter = gr.Number(value=0, visible=False)
51
- top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="Top-p (creativity)")
52
- temperature = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Temperature")
53
-
54
- with gr.Row():
55
- submit_btn = gr.Button("πŸš€ Ask")
56
- status_box = gr.Textbox(label="Status", interactive=False)
57
-
 
 
 
58
  inputs.submit(reset_textbox, [], [inputs, submit_btn], queue=False)
59
  inputs.submit(generate_response, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, status_box, inputs, submit_btn])
60
  submit_btn.click(reset_textbox, [], [inputs, submit_btn], queue=False)
61
  submit_btn.click(generate_response, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, status_box, inputs, submit_btn])
62
 
63
- demo.queue(max_size=10).launch()
 
 
 
 
 
 
 
 
 
14
  print(f"Detected language: {lang}")
15
 
16
  if lang == "bg":
17
+ user_input_translated = bg_to_en(user_input)[0]["translation_text"]
18
  else:
19
  user_input_translated = user_input
20
 
 
28
  response = generator(prompt, max_length=200, top_p=top_p, temperature=temperature, do_sample=True)[0]["generated_text"]
29
 
30
  if lang == "bg":
31
+ response = en_to_bg(response)[0]["translation_text"]
32
 
33
  chat_counter += 1
34
  history.append((user_input, response))
 
38
  def reset_textbox():
39
  return gr.update(value='', interactive=False), gr.update(interactive=False)
40
 
41
+ # Custom CSS to match MasterBrand website design
42
+ custom_css = """
43
+ /* Import Google Fonts */
44
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');
45
+
46
+ /* Global styles */
47
+ * {
48
+ font-family: 'Inter', sans-serif !important;
49
+ }
50
+
51
+ /* Main container styling */
52
+ .gradio-container {
53
+ background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%) !important;
54
+ min-height: 100vh !important;
55
+ }
56
+
57
+ /* Header styling */
58
+ .main-header {
59
+ background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%) !important;
60
+ padding: 2rem 0 !important;
61
+ text-align: center !important;
62
+ border-bottom: 2px solid #ff4d00 !important;
63
+ margin-bottom: 2rem !important;
64
+ }
65
+
66
+ .main-header h1 {
67
+ color: #ffffff !important;
68
+ font-size: 3rem !important;
69
+ font-weight: 800 !important;
70
+ margin-bottom: 0.5rem !important;
71
+ text-shadow: 0 0 20px rgba(255, 77, 0, 0.3) !important;
72
+ }
73
+
74
+ .main-header p {
75
+ color: #cccccc !important;
76
+ font-size: 1.2rem !important;
77
+ font-weight: 400 !important;
78
+ margin: 0 !important;
79
+ }
80
+
81
+ /* Chatbot container */
82
+ .chatbot-container {
83
+ background: rgba(42, 42, 42, 0.8) !important;
84
+ border: 2px solid #ff4d00 !important;
85
+ border-radius: 20px !important;
86
+ box-shadow: 0 10px 30px rgba(255, 77, 0, 0.2) !important;
87
+ margin-bottom: 2rem !important;
88
+ min-height: 400px !important;
89
+ }
90
+
91
+ /* Input styling */
92
+ .input-container {
93
+ background: rgba(42, 42, 42, 0.9) !important;
94
+ border: 2px solid #ff4d00 !important;
95
+ border-radius: 15px !important;
96
+ padding: 1rem !important;
97
+ margin-bottom: 1rem !important;
98
+ }
99
+
100
+ .input-container textarea {
101
+ background: #2a2a2a !important;
102
+ border: 1px solid #ff4d00 !important;
103
+ border-radius: 10px !important;
104
+ color: #ffffff !important;
105
+ font-size: 1.1rem !important;
106
+ padding: 1rem !important;
107
+ resize: none !important;
108
+ }
109
+
110
+ .input-container textarea:focus {
111
+ border-color: #ff6d20 !important;
112
+ box-shadow: 0 0 15px rgba(255, 77, 0, 0.3) !important;
113
+ outline: none !important;
114
+ }
115
+
116
+ /* Button styling */
117
+ .submit-button {
118
+ background: linear-gradient(135deg, #ff4d00 0%, #ff6d20 100%) !important;
119
+ border: none !important;
120
+ border-radius: 12px !important;
121
+ color: #ffffff !important;
122
+ font-size: 1.2rem !important;
123
+ font-weight: 600 !important;
124
+ padding: 1rem 2rem !important;
125
+ transition: all 0.3s ease !important;
126
+ box-shadow: 0 5px 15px rgba(255, 77, 0, 0.3) !important;
127
+ }
128
+
129
+ .submit-button:hover {
130
+ background: linear-gradient(135deg, #ff6d20 0%, #ff8d40 100%) !important;
131
+ transform: translateY(-2px) !important;
132
+ box-shadow: 0 8px 25px rgba(255, 77, 0, 0.4) !important;
133
+ }
134
+
135
+ /* Slider styling */
136
+ .slider-container {
137
+ background: rgba(42, 42, 42, 0.6) !important;
138
+ border: 1px solid #ff4d00 !important;
139
+ border-radius: 10px !important;
140
+ padding: 1rem !important;
141
+ margin-bottom: 1rem !important;
142
+ }
143
+
144
+ .slider-container label {
145
+ color: #ffffff !important;
146
+ font-weight: 600 !important;
147
+ font-size: 1rem !important;
148
+ margin-bottom: 0.5rem !important;
149
+ display: block !important;
150
+ }
151
+
152
+ /* Status box styling */
153
+ .status-container {
154
+ background: rgba(42, 42, 42, 0.8) !important;
155
+ border: 1px solid #4CAF50 !important;
156
+ border-radius: 10px !important;
157
+ padding: 1rem !important;
158
+ }
159
+
160
+ .status-container textarea {
161
+ background: transparent !important;
162
+ border: none !important;
163
+ color: #4CAF50 !important;
164
+ font-weight: 600 !important;
165
+ }
166
+
167
+ /* Advanced styling for chat messages */
168
+ .message {
169
+ animation: fadeInUp 0.5s ease-out !important;
170
+ }
171
+
172
+ @keyframes fadeInUp {
173
+ from {
174
+ opacity: 0;
175
+ transform: translateY(20px);
176
+ }
177
+ to {
178
+ opacity: 1;
179
+ transform: translateY(0);
180
+ }
181
+ }
182
+
183
+ /* Responsive design */
184
+ @media (max-width: 768px) {
185
+ .main-header h1 {
186
+ font-size: 2rem !important;
187
+ }
188
+
189
+ .main-header p {
190
+ font-size: 1rem !important;
191
+ }
192
+
193
+ .submit-button {
194
+ font-size: 1rem !important;
195
+ padding: 0.8rem 1.5rem !important;
196
+ }
197
+ }
198
+
199
+ /* Hide Gradio branding */
200
+ .footer {
201
+ display: none !important;
202
+ }
203
+
204
+ /* Custom scrollbar */
205
+ ::-webkit-scrollbar {
206
+ width: 8px;
207
+ }
208
+
209
+ ::-webkit-scrollbar-track {
210
+ background: #2a2a2a;
211
+ }
212
+
213
+ ::-webkit-scrollbar-thumb {
214
+ background: #ff4d00;
215
+ border-radius: 4px;
216
+ }
217
+
218
+ ::-webkit-scrollbar-thumb:hover {
219
+ background: #ff6d20;
220
+ }
221
+ """
222
+
223
+ # Enhanced theme matching MasterBrand
224
+ masterbrand_theme = gr.themes.Base(
225
+ primary_hue="orange",
226
+ secondary_hue="blue",
227
+ neutral_hue="slate",
228
+ ).set(
229
+ # Background colors
230
+ body_background_fill="#1a1a1a",
231
+ body_background_fill_dark="#1a1a1a",
232
+ background_fill_primary="#2a2a2a",
233
+ background_fill_primary_dark="#2a2a2a",
234
+ background_fill_secondary="#3a3a3a",
235
+ background_fill_secondary_dark="#3a3a3a",
236
+
237
+ # Button colors
238
+ button_primary_background_fill="#ff4d00",
239
+ button_primary_background_fill_dark="#ff4d00",
240
+ button_primary_background_fill_hover="#ff6d20",
241
+ button_primary_background_fill_hover_dark="#ff6d20",
242
+ button_primary_text_color="#ffffff",
243
+ button_primary_text_color_dark="#ffffff",
244
+
245
+ # Text colors
246
+ body_text_color="#ffffff",
247
+ body_text_color_dark="#ffffff",
248
+ body_text_color_subdued="#cccccc",
249
+ body_text_color_subdued_dark="#cccccc",
250
+
251
+ # Border and accent colors
252
+ border_color_accent="#ff4d00",
253
+ border_color_accent_dark="#ff4d00",
254
+ border_color_primary="#3a3a3a",
255
+ border_color_primary_dark="#3a3a3a",
256
+ color_accent="#ff4d00",
257
+ color_accent_soft="#ff4d00",
258
+
259
+ # Input colors
260
+ input_background_fill="#2a2a2a",
261
+ input_background_fill_dark="#2a2a2a",
262
+ input_background_fill_focus="#3a3a3a",
263
+ input_background_fill_focus_dark="#3a3a3a",
264
+ input_border_color="#ff4d00",
265
+ input_border_color_dark="#ff4d00",
266
+ input_border_color_focus="#ff6d20",
267
+ input_border_color_focus_dark="#ff6d20",
268
+
269
+ # Link colors
270
+ link_text_color="#ff4d00",
271
+ link_text_color_dark="#ff4d00",
272
+ link_text_color_active="#ff6d20",
273
+ link_text_color_active_dark="#ff6d20",
274
+ link_text_color_hover="#ff6d20",
275
+ link_text_color_hover_dark="#ff6d20",
276
+ link_text_color_visited="#ff4d00",
277
+ link_text_color_visited_dark="#ff4d00",
278
+
279
+ # Slider colors
280
+ slider_color="#ff4d00",
281
+ slider_color_dark="#ff4d00",
282
+ )
283
+
284
+ with gr.Blocks(theme=masterbrand_theme, css=custom_css, title="MasterBrand AI Assistant") as demo:
285
+ # Header section
286
+ gr.HTML("""
287
+ <div class="main-header">
288
+ <h1>πŸ›οΈ MASTERBRAND AI ASSISTANT</h1>
289
+ <p>Your Personal E-commerce Business Expert - Available in English & Bulgarian</p>
290
+ </div>
291
  """)
292
 
293
+ # Main chat interface
294
+ with gr.Row():
295
+ with gr.Column(scale=1):
296
+ chatbot = gr.Chatbot(
297
+ label="πŸ’¬ Chat with MasterBrand AI",
298
+ height=400,
299
+ elem_classes=["chatbot-container"]
300
+ )
301
+
302
+ with gr.Row():
303
+ inputs = gr.Textbox(
304
+ placeholder="Ask me anything about your e-commerce business... (e.g., 'What product should I sell?', 'How do I start dropshipping?')",
305
+ label="Your Question",
306
+ lines=2,
307
+ elem_classes=["input-container"]
308
+ )
309
+
310
+ with gr.Row():
311
+ submit_btn = gr.Button(
312
+ "πŸš€ Get Expert Advice",
313
+ variant="primary",
314
+ size="lg",
315
+ elem_classes=["submit-button"]
316
+ )
317
+ status_box = gr.Textbox(
318
+ label="Status",
319
+ interactive=False,
320
+ elem_classes=["status-container"]
321
+ )
322
+
323
+ # Advanced settings (collapsible)
324
+ with gr.Accordion("βš™οΈ Advanced Settings", open=False):
325
+ with gr.Row():
326
+ with gr.Column():
327
+ top_p = gr.Slider(
328
+ minimum=0.1,
329
+ maximum=1.0,
330
+ value=0.9,
331
+ step=0.05,
332
+ label="🎯 Creativity Level (Top-p)",
333
+ info="Higher values = more creative responses",
334
+ elem_classes=["slider-container"]
335
+ )
336
+ with gr.Column():
337
+ temperature = gr.Slider(
338
+ minimum=0.1,
339
+ maximum=2.0,
340
+ value=1.0,
341
+ step=0.1,
342
+ label="🌑️ Response Temperature",
343
+ info="Higher values = more varied responses",
344
+ elem_classes=["slider-container"]
345
+ )
346
+
347
+ # Hidden state variables
348
  state = gr.State([])
349
  chat_counter = gr.Number(value=0, visible=False)
350
+
351
+ # Footer
352
+ gr.HTML("""
353
+ <div style="text-align: center; padding: 2rem; color: #cccccc; border-top: 1px solid #3a3a3a; margin-top: 2rem;">
354
+ <p>πŸš€ Powered by MasterBrand AI Technology | Built for E-commerce Success</p>
355
+ <p style="font-size: 0.9rem; opacity: 0.7;">Get personalized advice for your online business journey</p>
356
+ </div>
357
+ """)
358
+
359
+ # Event handlers
360
  inputs.submit(reset_textbox, [], [inputs, submit_btn], queue=False)
361
  inputs.submit(generate_response, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, status_box, inputs, submit_btn])
362
  submit_btn.click(reset_textbox, [], [inputs, submit_btn], queue=False)
363
  submit_btn.click(generate_response, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter, status_box, inputs, submit_btn])
364
 
365
+ if __name__ == "__main__":
366
+ demo.queue(max_size=10).launch(
367
+ server_name="0.0.0.0",
368
+ server_port=7861,
369
+ share=False,
370
+ show_error=True
371
+ )
372
+
373
+