Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 87 |
-
|
| 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
|
| 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 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
button
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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",
|
| 222 |
-
|
|
|
|
|
|
|
| 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():
|