iro-malta07 commited on
Commit
de6e05c
·
verified ·
1 Parent(s): 1566f97

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ # Load model and tokenizer from Hugging Face
6
+ # model_name = "your-username/your-model-name" # replace with your model path
7
+ # tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ # model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
+
10
+ # Use id2label from the config
11
+ # id2label = model.config.id2label
12
+
13
+ # Inference function
14
+ def classify_text(text):
15
+ # inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
16
+ #with torch.no_grad():
17
+ # outputs = model(**inputs)
18
+ # probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
19
+ # pred_class = torch.argmax(probs, dim=1).item()
20
+ #confidence = probs[0, pred_class].item()
21
+ # label = id2label[pred_class]
22
+ # return f"Predicted Level: {label} (Confidence: {confidence:.2f})"
23
+ return f"Predicted Level: a2 (Confidence: 0.5)"
24
+
25
+ # Gradio interface
26
+ demo = gr.Interface(
27
+ fn=classify_text,
28
+ inputs=gr.Textbox(lines=4, placeholder="Schreibe etwas auf Deutsch..."),
29
+ outputs=gr.Textbox(label="Language Level Prediction"),
30
+ title="German Language Level Classifier",
31
+ description="Enter German text and get the predicted CEFR level (A1 to B2)."
32
+ )
33
+
34
+ # Launch app
35
+ demo.launch()