avram48 commited on
Commit
5b22d48
·
verified ·
1 Parent(s): b3ffcba

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +33 -0
  2. cefr_model.pth +3 -0
  3. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import DistilBertTokenizerFast, DistilBertForSequenceClassification, AutoConfig
4
+ import os
5
+
6
+ model_name = "distilbert-base-uncased"
7
+ model_path = "cefr_model.pth"
8
+ num_labels = 6
9
+ level_mapping = {0: 'A1', 1: 'A2', 2: 'B1', 3: 'B2', 4: 'C1', 5: 'C2'}
10
+
11
+ tokenizer = DistilBertTokenizerFast.from_pretrained(model_name)
12
+ config = AutoConfig.from_pretrained(model_name, num_labels=num_labels)
13
+ model = DistilBertForSequenceClassification.from_pretrained(model_name, config=config)
14
+ model.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')))
15
+ model.eval() # Set the model to evaluation mode
16
+
17
+ def predict_cefr(text):
18
+ inputs = tokenizer(text, padding=True, truncation=True, return_tensors="pt")
19
+ with torch.no_grad():
20
+ outputs = model(**inputs)
21
+ probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
22
+ predicted_class = torch.argmax(probabilities).item()
23
+ return level_mapping[predicted_class]
24
+
25
+ iface = gr.Interface(
26
+ fn=predict_cefr,
27
+ inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
28
+ outputs="text",
29
+ title="CEFR Level Prediction",
30
+ description="Enter some English text and I'll predict its CEFR level!"
31
+ )
32
+
33
+ iface.launch()
cefr_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fa983346b4c4c868a6393c3487ef1db0a480e7b7b2d8bf8c06ad29a4dc91770
3
+ size 267895464
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ pandas
4
+ scikit-learn
5
+ gradio
6
+ datasets
7
+ huggingface_hub