Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,23 @@
|
|
| 1 |
import os
|
| 2 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0"
|
| 3 |
|
| 4 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
# ---- Load model and tokenizer ----
|
| 8 |
model_name = "Mudasir692/mbart-eng-ur"
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
tokenizer = MBart50TokenizerFast.from_pretrained(model_name, src_lang="en_XX", tgt_lang="ur_PK")
|
| 11 |
-
model = MBartForConditionalGeneration.from_pretrained(model_name)
|
| 12 |
|
| 13 |
# ---- Translation function ----
|
| 14 |
def translate_to_urdu(text):
|
|
@@ -44,12 +53,17 @@ app = gr.Interface(
|
|
| 44 |
theme="soft",
|
| 45 |
css="""
|
| 46 |
body {
|
| 47 |
-
background: linear-gradient(
|
| 48 |
font-family: 'Segoe UI', sans-serif;
|
|
|
|
| 49 |
}
|
| 50 |
.gr-button-primary {
|
| 51 |
background-color: #1e3799 !important;
|
| 52 |
color: white !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
}
|
| 54 |
""",
|
| 55 |
)
|
|
|
|
| 1 |
import os
|
| 2 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0"
|
| 3 |
|
| 4 |
+
from transformers import (
|
| 5 |
+
MBart50TokenizerFast,
|
| 6 |
+
MBartForConditionalGeneration,
|
| 7 |
+
AutoConfig
|
| 8 |
+
)
|
| 9 |
import gradio as gr
|
| 10 |
|
| 11 |
# ---- Load model and tokenizer ----
|
| 12 |
model_name = "Mudasir692/mbart-eng-ur"
|
| 13 |
|
| 14 |
+
# Fix config issue (early_stopping = None)
|
| 15 |
+
config = AutoConfig.from_pretrained(model_name)
|
| 16 |
+
if getattr(config, "early_stopping", None) is None:
|
| 17 |
+
config.early_stopping = True
|
| 18 |
+
|
| 19 |
tokenizer = MBart50TokenizerFast.from_pretrained(model_name, src_lang="en_XX", tgt_lang="ur_PK")
|
| 20 |
+
model = MBartForConditionalGeneration.from_pretrained(model_name, config=config)
|
| 21 |
|
| 22 |
# ---- Translation function ----
|
| 23 |
def translate_to_urdu(text):
|
|
|
|
| 53 |
theme="soft",
|
| 54 |
css="""
|
| 55 |
body {
|
| 56 |
+
background: linear-gradient(135deg, #d1f2eb, #a3e4d7, #d6eaf8);
|
| 57 |
font-family: 'Segoe UI', sans-serif;
|
| 58 |
+
background-attachment: fixed;
|
| 59 |
}
|
| 60 |
.gr-button-primary {
|
| 61 |
background-color: #1e3799 !important;
|
| 62 |
color: white !important;
|
| 63 |
+
border-radius: 8px !important;
|
| 64 |
+
}
|
| 65 |
+
h1, h3 {
|
| 66 |
+
color: #0a3d62 !important;
|
| 67 |
}
|
| 68 |
""",
|
| 69 |
)
|