SagarVelamuri commited on
Commit
c0b713d
·
verified ·
1 Parent(s): 489d5dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -33
app.py CHANGED
@@ -83,12 +83,11 @@ _model_cache = {}
83
  def load_model(model_name: str):
84
  if model_name in _model_cache:
85
  return _model_cache[model_name]
86
- token = os.getenv("hf_token")
87
- print(token)
88
- tok = AutoTokenizer.from_pretrained("ai4bharat/indictrans2-en-indic-1B", trust_remote_code=True)
89
  mdl = AutoModelForSeq2SeqLM.from_pretrained(
90
  model_name, trust_remote_code=True,
91
- low_cpu_mem_usage=True, dtype=dtype, token=token
92
  ).to(device).eval()
93
 
94
  # Fix vocab
@@ -176,40 +175,56 @@ THEME = gr.themes.Soft(
176
  )
177
 
178
  CUSTOM_CSS = """
 
179
  #hdr { text-align:center; padding:16px; }
180
  #hdr h1 { font-size:24px; font-weight:700; color:#f9fafb; margin:0; }
181
  #hdr p { font-size:14px; color:#9ca3af; margin-top:4px; }
182
  .panel { border:1px solid #1f2937; border-radius:10px; padding:12px; background:#111827; box-shadow:0 1px 2px rgba(0,0,0,0.4);}
183
  .panel h2 { font-size:16px; font-weight:600; margin-bottom:6px; color:#f3f4f6; }
184
- /* Ensure textbox uses dark bg + light fg */
185
- textarea, .gr-textbox textarea { background:#0b0f19 !important; color:#f9fafb !important; border-radius:8px !important; border:1px solid #374151 !important; font-size:15px !important; line-height:1.55; }
186
- /* Button styling */
187
- button, .gr-button { border-radius:8px !important; font-weight:600 !important; }
188
- button, .gr-button { color:#fff !important; background-color:#2563eb !important; border:none !important; }
189
- button.secondary, .gr-button.secondary { background-color:#374151 !important; }
190
- button:hover, .gr-button:hover { opacity:0.92; }
191
- /* Dropdowns & Selects */
192
- select, .gr-input select, .form-select, .gradio-dropdown { background:#0b0f19 !important; color:#f9fafb !important; border:1.5px solid #374151 !important; border-radius:8px !important; font-size:15px !important; font-weight:600 !important; }
193
- /* Make dropdown options clear (browsers may ignore some CSS here) */
194
- option { background:#0b0f19; color:#f9fafb; }
195
- /* Sliders and labels */
196
- input[type=range], .gr-slider input[type=range] { accent-color: #2563eb; }
197
- .gr-slider-label, .gradio-slider label, .gr-slider label,
198
- .gr-input label, label, .form-label, .block-label { color:#f9fafb !important; font-weight:600; font-size:15px !important; }
199
- .gradio-slider .value, .gr-slider .value { color:#f9fafb !important; font-weight:600 !important; }
200
- .gr-slider { background:#1e293b !important; border-radius:6px !important; }
201
- /* General form inputs */
202
- input, .gr-input input, .gradio-input { background:#0b0f19 !important; color:#f9fafb !important; border:1.5px solid #374151 !important; border-radius:8px !important; }
203
- /* Remove opacity on any label elements (for clarity) */
204
- label, .form-label, .block-label { opacity:1 !important; }
205
- /* Gradio fix: force all form text to be light */
206
- .gradio-container, .gr-block, .gr-form, .gr-form label, .gr-block label, .gradio-form label, .form-label, .block-label, .block-info {
207
- color:#f9fafb !important;
 
 
 
 
 
 
 
 
 
 
 
 
208
  }
209
- /* Added: dropdown arrow color for some UIs */
210
- select { background-image: linear-gradient(45deg, #f9fafb 50%, transparent 50%), linear-gradient(135deg, #f9fafb 50%, transparent 50%); background-position: right 16px top 14px, right 12px top 14px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
211
- """
212
 
 
 
 
 
 
 
213
 
214
  # --------------------- UI ---------------------
215
  with gr.Blocks(theme=THEME, css=CUSTOM_CSS, title="EN → HI/TE Translator") as demo:
@@ -218,8 +233,10 @@ with gr.Blocks(theme=THEME, css=CUSTOM_CSS, title="EN → HI/TE Translator") as
218
  gr.Markdown("<p>IndicTrans2 with batch sentence decomposition</p>")
219
 
220
  model_choice = gr.Dropdown(
221
- label="Choose Model", choices=list(MODELS.keys()),
222
- value="Default (Public)"
 
 
223
  )
224
 
225
  with gr.Row():
 
83
  def load_model(model_name: str):
84
  if model_name in _model_cache:
85
  return _model_cache[model_name]
86
+
87
+ tok = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, use_fast=True)
 
88
  mdl = AutoModelForSeq2SeqLM.from_pretrained(
89
  model_name, trust_remote_code=True,
90
+ low_cpu_mem_usage=True, dtype=dtype
91
  ).to(device).eval()
92
 
93
  # Fix vocab
 
175
  )
176
 
177
  CUSTOM_CSS = """
178
+ /* Header + Panels */
179
  #hdr { text-align:center; padding:16px; }
180
  #hdr h1 { font-size:24px; font-weight:700; color:#f9fafb; margin:0; }
181
  #hdr p { font-size:14px; color:#9ca3af; margin-top:4px; }
182
  .panel { border:1px solid #1f2937; border-radius:10px; padding:12px; background:#111827; box-shadow:0 1px 2px rgba(0,0,0,0.4);}
183
  .panel h2 { font-size:16px; font-weight:600; margin-bottom:6px; color:#f3f4f6; }
184
+
185
+ /* Inputs */
186
+ textarea { background:#0b0f19 !important; color:#f9fafb !important; border-radius:8px !important; border:1px solid #374151 !important; font-size:15px !important; line-height:1.55; }
187
+ button { border-radius:8px !important; font-weight:600 !important; }
188
+
189
+ /* Make all component labels readable on dark bg */
190
+ .gradio-container label,
191
+ .gradio-container .label,
192
+ .gradio-container .block-title,
193
+ .gradio-container .prose h2,
194
+ .gradio-container .prose h3 {
195
+ color:#e5e7eb !important;
196
+ }
197
+
198
+ /* --- Dropdown: dark text on white field/menu --- */
199
+ #model_dd .wrap,
200
+ #model_dd .container {
201
+ background:#ffffff !important;
202
+ border:1px solid #374151 !important;
203
+ border-radius:8px !important;
204
+ }
205
+ #model_dd input,
206
+ #model_dd .value,
207
+ #model_dd ::placeholder,
208
+ #model_dd select,
209
+ #model_dd option {
210
+ color:#111827 !important; /* dark text */
211
+ background:#ffffff !important;
212
+ }
213
+ #model_dd .options,
214
+ #model_dd .options .item {
215
+ background:#ffffff !important;
216
+ color:#111827 !important;
217
+ }
218
+ #model_dd label { /* the component's own label */
219
+ color:#e5e7eb !important;
220
  }
 
 
 
221
 
222
+ /* Sliders: keep labels visible */
223
+ .gradio-container .range-block label,
224
+ .gradio-container .gr-slider label {
225
+ color:#e5e7eb !important;
226
+ }
227
+ """
228
 
229
  # --------------------- UI ---------------------
230
  with gr.Blocks(theme=THEME, css=CUSTOM_CSS, title="EN → HI/TE Translator") as demo:
 
233
  gr.Markdown("<p>IndicTrans2 with batch sentence decomposition</p>")
234
 
235
  model_choice = gr.Dropdown(
236
+ label="Choose Model",
237
+ choices=list(MODELS.keys()),
238
+ value="Default (Public)",
239
+ elem_id="model_dd" # <-- for targeted styling
240
  )
241
 
242
  with gr.Row():