Skip to content

Commit 65af6e9

Browse files
Merge pull request #6 from Md-Emon-Hasan/master
fix ui
2 parents 8773118 + 6e94865 commit 65af6e9

7 files changed

Lines changed: 113 additions & 43 deletions

File tree

app.png

67.9 KB
Loading

app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
model.eval()
2727
print("Model & Tokenizer loaded.")
2828

29-
# Routes
3029
@app.route("/")
3130
def index():
3231
return render_template("index.html")

demo.mp4

-2.61 MB
Binary file not shown.

notebook/Experiment.ipynb

Lines changed: 100 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -169,37 +169,25 @@
169169
"cell_type": "markdown",
170170
"metadata": {},
171171
"source": [
172-
"### ***Importing required modules for model training and evaluation***"
172+
"### ***Loading the dataset for English to Spanish translation task***"
173173
]
174174
},
175175
{
176176
"cell_type": "code",
177-
"execution_count": null,
178-
"metadata": {
179-
"id": "AWfPzkluGKuk"
180-
},
181-
"outputs": [],
182-
"source": [
183-
"from transformers import AutoTokenizer\n",
184-
"from transformers import AutoModelForSeq2SeqLM\n",
185-
"from transformers import Seq2SeqTrainer\n",
186-
"from transformers import Seq2SeqTrainingArguments\n",
187-
"from transformers import DataCollatorForSeq2Seq\n",
188-
"from datasets import load_dataset\n",
189-
"from peft import get_peft_model\n",
190-
"from peft import LoraConfig\n",
191-
"from peft import TaskType\n",
192-
"from peft import prepare_model_for_kbit_training\n",
193-
"import evaluate\n",
194-
"import numpy as np\n",
195-
"import torch"
196-
]
197-
},
198-
{
199-
"cell_type": "markdown",
177+
"execution_count": 1,
200178
"metadata": {},
179+
"outputs": [
180+
{
181+
"name": "stderr",
182+
"output_type": "stream",
183+
"text": [
184+
"c:\\Users\\emon1\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
185+
" from .autonotebook import tqdm as notebook_tqdm\n"
186+
]
187+
}
188+
],
201189
"source": [
202-
"### ***Loading the dataset for English to Spanish translation task***"
190+
"from datasets import load_dataset"
203191
]
204192
},
205193
{
@@ -316,6 +304,15 @@
316304
"### ***Loading pre-trained model and tokenizer from Hugging Face Model Hub***"
317305
]
318306
},
307+
{
308+
"cell_type": "code",
309+
"execution_count": null,
310+
"metadata": {},
311+
"outputs": [],
312+
"source": [
313+
"from transformers import AutoTokenizer"
314+
]
315+
},
319316
{
320317
"cell_type": "code",
321318
"execution_count": null,
@@ -560,6 +557,15 @@
560557
"### ***Load Pretrained Model***"
561558
]
562559
},
560+
{
561+
"cell_type": "code",
562+
"execution_count": null,
563+
"metadata": {},
564+
"outputs": [],
565+
"source": [
566+
"from transformers import AutoModelForSeq2SeqLM"
567+
]
568+
},
563569
{
564570
"cell_type": "code",
565571
"execution_count": null,
@@ -636,6 +642,15 @@
636642
"### ***Apply PEFT + LoRA Configuration***"
637643
]
638644
},
645+
{
646+
"cell_type": "code",
647+
"execution_count": null,
648+
"metadata": {},
649+
"outputs": [],
650+
"source": [
651+
"from peft import LoraConfig, TaskType"
652+
]
653+
},
639654
{
640655
"cell_type": "code",
641656
"execution_count": null,
@@ -647,13 +662,22 @@
647662
"lora_config = LoraConfig(\n",
648663
" r=8,\n",
649664
" lora_alpha=32,\n",
650-
" target_modules=[\"q_proj\", \"v_proj\"], # Adjust for model type\n",
665+
" target_modules=[\"q_proj\", \"v_proj\"],\n",
651666
" lora_dropout=0.1,\n",
652667
" bias=\"none\",\n",
653668
" task_type=TaskType.SEQ_2_SEQ_LM\n",
654669
")"
655670
]
656671
},
672+
{
673+
"cell_type": "code",
674+
"execution_count": null,
675+
"metadata": {},
676+
"outputs": [],
677+
"source": [
678+
"from peft import get_peft_model"
679+
]
680+
},
657681
{
658682
"cell_type": "code",
659683
"execution_count": 8,
@@ -685,6 +709,16 @@
685709
"### ***Training Arguments***"
686710
]
687711
},
712+
{
713+
"cell_type": "code",
714+
"execution_count": null,
715+
"metadata": {},
716+
"outputs": [],
717+
"source": [
718+
"from transformers import Seq2SeqTrainingArguments\n",
719+
"import torch"
720+
]
721+
},
688722
{
689723
"cell_type": "code",
690724
"execution_count": null,
@@ -705,7 +739,7 @@
705739
" logging_steps=100,\n",
706740
" save_strategy=\"epoch\",\n",
707741
" predict_with_generate=True,\n",
708-
" fp16=torch.cuda.is_available(), # Optional: if CUDA available\n",
742+
" fp16=torch.cuda.is_available(),\n",
709743
")"
710744
]
711745
},
@@ -716,6 +750,15 @@
716750
"### ***Data Collator***"
717751
]
718752
},
753+
{
754+
"cell_type": "code",
755+
"execution_count": null,
756+
"metadata": {},
757+
"outputs": [],
758+
"source": [
759+
"from transformers import DataCollatorForSeq2Seq"
760+
]
761+
},
719762
{
720763
"cell_type": "code",
721764
"execution_count": null,
@@ -734,6 +777,16 @@
734777
"### ***Evaluation Metric: BLEU***"
735778
]
736779
},
780+
{
781+
"cell_type": "code",
782+
"execution_count": null,
783+
"metadata": {},
784+
"outputs": [],
785+
"source": [
786+
"import evaluate\n",
787+
"import numpy as np"
788+
]
789+
},
737790
{
738791
"cell_type": "code",
739792
"execution_count": null,
@@ -753,7 +806,7 @@
753806
" decoded_preds = tokenizer.batch_decode(preds, skip_special_tokens=True)\n",
754807
" decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)\n",
755808
"\n",
756-
" # Important: BLEU expects list of strings for preds and list of list of strings for refs\n",
809+
" # BLEU expects list of strings for preds and list of list of strings for refs\n",
757810
" # So wrap references inside list\n",
758811
" references = [[ref] for ref in decoded_labels]\n",
759812
"\n",
@@ -769,6 +822,15 @@
769822
"### ***Trainer Setup***"
770823
]
771824
},
825+
{
826+
"cell_type": "code",
827+
"execution_count": null,
828+
"metadata": {},
829+
"outputs": [],
830+
"source": [
831+
"from transformers import Seq2SeqTrainer"
832+
]
833+
},
772834
{
773835
"cell_type": "code",
774836
"execution_count": null,
@@ -1406,7 +1468,16 @@
14061468
"name": "python3"
14071469
},
14081470
"language_info": {
1409-
"name": "python"
1471+
"codemirror_mode": {
1472+
"name": "ipython",
1473+
"version": 3
1474+
},
1475+
"file_extension": ".py",
1476+
"mimetype": "text/x-python",
1477+
"name": "python",
1478+
"nbconvert_exporter": "python",
1479+
"pygments_lexer": "ipython3",
1480+
"version": "3.11.9"
14101481
},
14111482
"widgets": {
14121483
"application/vnd.jupyter.widget-state+json": {

static/js/script.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ function translateText() {
22
const input = document.getElementById("inputText").value.trim();
33
const output = document.getElementById("output");
44
if (!input) {
5-
output.innerHTML = "<span class='text-warning'>⚠️ Please enter some text!</span>";
5+
output.innerHTML = "<span class='text-warning'>Please enter some text!</span>";
66
return;
77
}
88

9-
output.innerHTML = "<em>Translating...</em>";
9+
output.innerHTML = "<em>Translating...</em>";
1010

1111
fetch("/translate", {
1212
method: "POST",
@@ -16,12 +16,12 @@ function translateText() {
1616
.then((res) => res.json())
1717
.then((data) => {
1818
if (data.translation) {
19-
output.innerHTML = `<strong>Translation:</strong><br>${data.translation}`;
19+
output.innerHTML = `<strong>Translation:</strong><br>${data.translation}`;
2020
} else {
21-
output.innerHTML = `<span class="text-danger">Error: ${data.error}</span>`;
21+
output.innerHTML = `<span class="text-danger">Error: ${data.error}</span>`;
2222
}
2323
})
2424
.catch((err) => {
25-
output.innerHTML = "<span class='text-danger'>⚠️ Failed to translate.</span>";
25+
output.innerHTML = "<span class='text-danger'>Failed to translate.</span>";
2626
});
2727
}

templates/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<title>🌐 Translatica</title>
5+
<title>Translatica</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<!-- Bootstrap CDN -->
88
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
@@ -17,15 +17,15 @@
1717
<div class="overlay"></div>
1818

1919
<div class="content">
20-
<div class="title">🌐 Translatica</div>
20+
<div class="title">Translatica</div>
2121
<div class="subtitle">
22-
English ➡️ Spanish Translation | Fine-tuned using LoRA + PEFT
22+
English Spanish Translation | Fine-tuned using LoRA + PEFT
2323
</div>
2424

2525

2626
<div class="form-container shadow-lg">
27-
<textarea id="inputText" class="form-control mb-3" placeholder="✍️ Enter your text here..."></textarea>
28-
<button class="btn" onclick="translateText()">🚀 Translate</button>
27+
<textarea id="inputText" class="form-control mb-3" placeholder="Enter your text here..."></textarea>
28+
<button class="btn" onclick="translateText()">Translate</button>
2929
<div id="output" class="mt-4"></div>
3030
</div>
3131
</div>

train.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
lora_config = LoraConfig(
3838
r=8,
3939
lora_alpha=32,
40-
target_modules=["q_proj", "v_proj"], # Adjust for model type
40+
target_modules=["q_proj", "v_proj"],
4141
lora_dropout=0.1,
4242
bias="none",
4343
task_type=TaskType.SEQ_2_SEQ_LM
@@ -59,7 +59,7 @@
5959
logging_steps=100,
6060
save_strategy="epoch",
6161
predict_with_generate=True,
62-
fp16=torch.cuda.is_available(), # Optional: if CUDA available
62+
fp16=torch.cuda.is_available(),
6363
)
6464

6565
# Data Collator
@@ -77,7 +77,7 @@ def compute_metrics(eval_preds):
7777
decoded_preds = tokenizer.batch_decode(preds, skip_special_tokens=True)
7878
decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)
7979

80-
# Important: BLEU expects list of strings for preds and list of list of strings for refs
80+
# BLEU expects list of strings for preds and list of list of strings for refs
8181
# So wrap references inside list
8282
references = [[ref] for ref in decoded_labels]
8383

0 commit comments

Comments
 (0)