abdull4h commited on
Commit
cc9b8ae
ยท
verified ยท
1 Parent(s): dadc247

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -31
app.py CHANGED
@@ -64,24 +64,29 @@ def load_models():
64
  def clean_response(text):
65
  # Step 1: Aggressively remove the common metadata pattern at the beginning
66
  text = re.sub(r'^\s*[\?ุŸ]\s*ู…ูˆุถูˆุน:.*?ุงู„ุชุงู„ูŠ:\s*[^ุŸ?]*[ุŸ?]\s*[^\n]*\d{4},\s*\d{1,2}:\d{2}\s*[apm]+\s*', '', text)
 
67
 
68
  # Step 2: Remove date and timestamp patterns
69
  text = re.sub(r'\d{1,2}\s+[^ ]+\s+\d{4}\s*[-,]\s*\d{1,2}:\d{2}\s*[ุตู…aApP][ู…mMnN]?', '', text)
70
 
71
- # Step 3: Remove website references
 
 
 
 
72
  text = re.sub(r'[-โ€“โ€”]\s*ู…ูˆู‚ุน\s+[^\n]+', '', text)
73
  text = re.sub(r'[-โ€“โ€”]\s*[^\n]*ุงู„ู…ุตุทุจู‡[^\n]*', '', text)
74
 
75
- # Step 4: Remove unrelated questions that might appear
76
  text = re.sub(r'ู…ู† ู‡ูˆ [^ุŸ?]+\ุŸ', '', text)
77
  text = re.sub(r'ู…ู† ู‡ูŠ [^ุŸ?]+\ุŸ', '', text)
78
  text = re.sub(r'ู…ุง ู‡ูˆ [^ุŸ?]+\ุŸ', '', text)
79
  text = re.sub(r'ู…ุง ู‡ูŠ [^ุŸ?]+\ุŸ', '', text)
80
 
81
- # Step 5: Clean up format and spacing
82
  text = re.sub(r'\s+', ' ', text).strip()
83
 
84
- # If text begins with a colon or similar punctuation, clean it
85
  text = re.sub(r'^[:.ุŒ,ุ›;-]+\s*', '', text)
86
 
87
  return text
@@ -134,22 +139,30 @@ def set_example3():
134
  def set_example4():
135
  return "ู…ุงู‡ูˆ ุดู‡ุฑ ุฑู…ุถุงู†ุŸ"
136
 
137
- # Create custom CSS that fixes text visibility while matching the current look
138
  custom_css = """
 
 
 
 
139
  /* Enhanced styles for Arabic Cohere model interface */
140
  :root {
141
  --primary-color: #1F4287;
142
  --secondary-color: #278EA5;
143
  --bg-color: #f9fafb;
144
  --border-color: #d1d5db;
145
- --btn-primary: #2C5282;
146
- --btn-secondary: #E2E8F0;
 
 
 
 
147
  --text-color: #000000;
148
  }
149
 
150
  /* Base styles */
151
  body, html {
152
- font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
153
  margin: 0;
154
  padding: 0;
155
  background-color: var(--bg-color);
@@ -157,9 +170,11 @@ body, html {
157
  }
158
 
159
  /* Typography */
160
- h1, h2, h3 {
 
161
  color: var(--primary-color);
162
  text-align: center;
 
163
  }
164
 
165
  /* Fix input and output containers */
@@ -171,61 +186,92 @@ h1, h2, h3 {
171
  background-color: white;
172
  }
173
 
174
- /* CRITICAL FIX: Make sure text is visible in textboxes */
175
  textarea, .output-text {
176
- font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif !important;
177
  color: black !important;
178
  background-color: white !important;
179
  border: 1px solid #d1d5db !important;
180
- padding: 10px !important;
181
  font-size: 16px !important;
182
- line-height: 1.5 !important;
183
- border-radius: 6px !important;
184
  width: 100% !important;
185
  direction: rtl !important;
186
  min-height: 80px !important;
 
 
187
  }
188
 
189
  /* Ensure text and placeholder are visible */
190
  textarea::placeholder {
191
  color: #9ca3af !important;
192
  opacity: 1 !important;
 
193
  }
194
 
195
- /* Button styling to match current design */
196
  button {
197
- border-radius: 6px !important;
198
- padding: 8px 16px !important;
199
  font-weight: 600 !important;
200
- transition: all 0.2s !important;
 
 
 
 
 
201
  }
202
 
203
- button.primary {
204
- background-color: var(--btn-primary) !important;
 
 
205
  color: white !important;
206
  border: none !important;
 
 
 
 
 
207
  }
208
 
209
- button.secondary {
210
- background-color: var(--btn-secondary) !important;
211
- color: var(--primary-color) !important;
212
- border: 1px solid var(--border-color) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  }
214
 
215
  /* Example buttons styling */
216
  .example-btn {
217
- background-color: #f8fafc !important;
218
- border: 1px solid #cbd5e1 !important;
219
  color: var(--primary-color) !important;
220
  padding: 8px 12px !important;
221
  border-radius: 6px !important;
222
  margin: 4px !important;
223
  font-size: 14px !important;
 
224
  }
225
 
226
  .example-btn:hover {
227
- background-color: #f1f5f9 !important;
228
- border-color: #94a3b8 !important;
229
  }
230
 
231
  /* Layout containers */
@@ -251,9 +297,19 @@ button.secondary {
251
  display: block !important;
252
  opacity: 1 !important;
253
  }
 
 
 
 
 
 
 
 
 
 
254
  """
255
 
256
- # Create a Gradio interface that matches the current design
257
  with gr.Blocks(css=custom_css, title="Cohere Arabic Model") as demo:
258
  gr.Markdown("""# โญ ู†ู…ูˆุฐุฌ ุฃุฑุญุจ ู„ู„ุบุฉ ุงู„ุนุฑุจูŠุฉ | Command R7B Arabic Model""")
259
 
@@ -277,8 +333,8 @@ with gr.Blocks(css=custom_css, title="Cohere Arabic Model") as demo:
277
  ex4 = gr.Button("ู…ุงู‡ูˆ ุดู‡ุฑ ุฑู…ุถุงู†ุŸ", elem_classes=["example-btn"])
278
 
279
  with gr.Row():
280
- submit_btn = gr.Button("ุชูˆู„ูŠุฏ ุงู„ู†ุต | Generate", elem_classes=["primary"])
281
- clear_btn = gr.Button("ู…ุณุญ | Clear", elem_classes=["secondary"])
282
 
283
  with gr.Column():
284
  output_text = gr.Textbox(
 
64
  def clean_response(text):
65
  # Step 1: Aggressively remove the common metadata pattern at the beginning
66
  text = re.sub(r'^\s*[\?ุŸ]\s*ู…ูˆุถูˆุน:.*?ุงู„ุชุงู„ูŠ:\s*[^ุŸ?]*[ุŸ?]\s*[^\n]*\d{4},\s*\d{1,2}:\d{2}\s*[apm]+\s*', '', text)
67
+ text = re.sub(r'^\s*[\?ุŸ]\s*ู…ู†ุชุฏูŠุงุช.*?ุญุงุฆู„.*?[^\n]*\d{4},\s*\d{1,2}:\d{2}', '', text)
68
 
69
  # Step 2: Remove date and timestamp patterns
70
  text = re.sub(r'\d{1,2}\s+[^ ]+\s+\d{4}\s*[-,]\s*\d{1,2}:\d{2}\s*[ุตู…aApP][ู…mMnN]?', '', text)
71
 
72
+ # Step 3: Remove forum metadata
73
+ text = re.sub(r'^\s*[\?ุŸ]\s*[^\n]+:\s*[^\n]+\?\s*', '', text)
74
+ text = re.sub(r'ู…ู†ุชุฏูŠุงุช.*?ู†ูˆุฑ[^\n]*$', '', text)
75
+
76
+ # Step 4: Remove website references
77
  text = re.sub(r'[-โ€“โ€”]\s*ู…ูˆู‚ุน\s+[^\n]+', '', text)
78
  text = re.sub(r'[-โ€“โ€”]\s*[^\n]*ุงู„ู…ุตุทุจู‡[^\n]*', '', text)
79
 
80
+ # Step 5: Remove unrelated questions that might appear
81
  text = re.sub(r'ู…ู† ู‡ูˆ [^ุŸ?]+\ุŸ', '', text)
82
  text = re.sub(r'ู…ู† ู‡ูŠ [^ุŸ?]+\ุŸ', '', text)
83
  text = re.sub(r'ู…ุง ู‡ูˆ [^ุŸ?]+\ุŸ', '', text)
84
  text = re.sub(r'ู…ุง ู‡ูŠ [^ุŸ?]+\ุŸ', '', text)
85
 
86
+ # Step 6: Clean up format and spacing
87
  text = re.sub(r'\s+', ' ', text).strip()
88
 
89
+ # Step 7: If text begins with punctuation, clean it
90
  text = re.sub(r'^[:.ุŒ,ุ›;-]+\s*', '', text)
91
 
92
  return text
 
139
  def set_example4():
140
  return "ู…ุงู‡ูˆ ุดู‡ุฑ ุฑู…ุถุงู†ุŸ"
141
 
142
+ # Create custom CSS with enhanced fonts and distinctive buttons
143
  custom_css = """
144
+ /* Import improved Arabic fonts from Google */
145
+ @import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap');
146
+ @import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600&display=swap');
147
+
148
  /* Enhanced styles for Arabic Cohere model interface */
149
  :root {
150
  --primary-color: #1F4287;
151
  --secondary-color: #278EA5;
152
  --bg-color: #f9fafb;
153
  --border-color: #d1d5db;
154
+ --btn-primary: #2563EB; /* Bright blue */
155
+ --btn-secondary: #6B7280; /* Gray */
156
+ --btn-primary-hover: #1D4ED8;
157
+ --btn-secondary-hover: #4B5563;
158
+ --example-btn-bg: #F3F4F6;
159
+ --example-btn-border: #D1D5DB;
160
  --text-color: #000000;
161
  }
162
 
163
  /* Base styles */
164
  body, html {
165
+ font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Arial', sans-serif !important;
166
  margin: 0;
167
  padding: 0;
168
  background-color: var(--bg-color);
 
170
  }
171
 
172
  /* Typography */
173
+ h1, h2, h3, button, label {
174
+ font-family: 'Tajawal', 'IBM Plex Sans Arabic', 'Arial', sans-serif !important;
175
  color: var(--primary-color);
176
  text-align: center;
177
+ font-weight: 700 !important;
178
  }
179
 
180
  /* Fix input and output containers */
 
186
  background-color: white;
187
  }
188
 
189
+ /* CRITICAL FIX: Make sure text is visible in textboxes with better fonts */
190
  textarea, .output-text {
191
+ font-family: 'IBM Plex Sans Arabic', 'Tajawal', 'Arial', sans-serif !important;
192
  color: black !important;
193
  background-color: white !important;
194
  border: 1px solid #d1d5db !important;
195
+ padding: 12px !important;
196
  font-size: 16px !important;
197
+ line-height: 1.6 !important;
198
+ border-radius: 8px !important;
199
  width: 100% !important;
200
  direction: rtl !important;
201
  min-height: 80px !important;
202
+ font-weight: 500 !important;
203
+ letter-spacing: 0.2px !important;
204
  }
205
 
206
  /* Ensure text and placeholder are visible */
207
  textarea::placeholder {
208
  color: #9ca3af !important;
209
  opacity: 1 !important;
210
+ font-family: 'IBM Plex Sans Arabic', 'Tajawal', 'Arial', sans-serif !important;
211
  }
212
 
213
+ /* Button styling to match current design but more distinct */
214
  button {
215
+ border-radius: 8px !important;
216
+ padding: 10px 20px !important;
217
  font-weight: 600 !important;
218
+ transition: all 0.2s ease !important;
219
+ cursor: pointer !important;
220
+ text-align: center !important;
221
+ font-size: 15px !important;
222
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
223
+ margin: 5px !important;
224
  }
225
 
226
+ /* SPECIAL STYLING FOR GENERATE/CLEAR BUTTONS */
227
+ /* Generate Button - Distinctive styling */
228
+ #generate-btn {
229
+ background: linear-gradient(135deg, #2563EB, #3B82F6) !important;
230
  color: white !important;
231
  border: none !important;
232
+ font-weight: 700 !important;
233
+ padding: 12px 24px !important;
234
+ box-shadow: 0 4px 6px rgba(37, 99, 235, 0.25) !important;
235
+ transform: translateY(0) !important;
236
+ font-size: 16px !important;
237
  }
238
 
239
+ #generate-btn:hover {
240
+ background: linear-gradient(135deg, #1D4ED8, #2563EB) !important;
241
+ box-shadow: 0 6px 8px rgba(37, 99, 235, 0.3) !important;
242
+ transform: translateY(-2px) !important;
243
+ }
244
+
245
+ /* Clear Button - Distinctive styling */
246
+ #clear-btn {
247
+ background-color: #F3F4F6 !important;
248
+ color: #4B5563 !important;
249
+ border: 1px solid #D1D5DB !important;
250
+ font-weight: 600 !important;
251
+ padding: 12px 24px !important;
252
+ font-size: 16px !important;
253
+ }
254
+
255
+ #clear-btn:hover {
256
+ background-color: #E5E7EB !important;
257
+ color: #374151 !important;
258
  }
259
 
260
  /* Example buttons styling */
261
  .example-btn {
262
+ background-color: var(--example-btn-bg) !important;
263
+ border: 1px solid var(--example-btn-border) !important;
264
  color: var(--primary-color) !important;
265
  padding: 8px 12px !important;
266
  border-radius: 6px !important;
267
  margin: 4px !important;
268
  font-size: 14px !important;
269
+ font-weight: 500 !important;
270
  }
271
 
272
  .example-btn:hover {
273
+ background-color: #E5E7EB !important;
274
+ border-color: #9CA3AF !important;
275
  }
276
 
277
  /* Layout containers */
 
297
  display: block !important;
298
  opacity: 1 !important;
299
  }
300
+
301
+ /* Improved labels */
302
+ label {
303
+ font-size: 16px !important;
304
+ font-weight: 600 !important;
305
+ margin-bottom: 5px !important;
306
+ display: block !important;
307
+ text-align: right !important;
308
+ color: #1F2937 !important;
309
+ }
310
  """
311
 
312
+ # Create a Gradio interface that matches the current design with better fonts
313
  with gr.Blocks(css=custom_css, title="Cohere Arabic Model") as demo:
314
  gr.Markdown("""# โญ ู†ู…ูˆุฐุฌ ุฃุฑุญุจ ู„ู„ุบุฉ ุงู„ุนุฑุจูŠุฉ | Command R7B Arabic Model""")
315
 
 
333
  ex4 = gr.Button("ู…ุงู‡ูˆ ุดู‡ุฑ ุฑู…ุถุงู†ุŸ", elem_classes=["example-btn"])
334
 
335
  with gr.Row():
336
+ submit_btn = gr.Button("ุชูˆู„ูŠุฏ ุงู„ู†ุต | Generate", elem_id="generate-btn")
337
+ clear_btn = gr.Button("ู…ุณุญ | Clear", elem_id="clear-btn")
338
 
339
  with gr.Column():
340
  output_text = gr.Textbox(