Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
-
from transformers import pipeline
|
4 |
from typing import List, Dict, Any
|
5 |
import torch
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
merged_tokens = []
|
9 |
for token in tokens:
|
10 |
if merged_tokens and token['entity'].startswith('I-') and merged_tokens[-1]['entity'].endswith(token['entity'][2:]):
|
@@ -19,8 +27,8 @@ def merge_tokens(tokens: List[Dict[str, any]]) -> List[Dict[str, any]]:
|
|
19 |
# Determine device
|
20 |
device = 0 if torch.cuda.is_available() else -1
|
21 |
|
22 |
-
# Initialize
|
23 |
-
get_completion = pipeline("ner", model=
|
24 |
|
25 |
@spaces.GPU(duration=120)
|
26 |
def ner(input: str) -> Dict[str, Any]:
|
@@ -35,7 +43,7 @@ def ner(input: str) -> Dict[str, Any]:
|
|
35 |
title = """<h1 id="title"> Bangla Legal Entity Recognition </h1>"""
|
36 |
|
37 |
description = """
|
38 |
-
- The model used for Recognizing entities [
|
39 |
"""
|
40 |
|
41 |
css = '''
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForTokenClassification
|
4 |
from typing import List, Dict, Any
|
5 |
import torch
|
6 |
|
7 |
+
# Define the model and tokenizer
|
8 |
+
model_name = "kazalbrur/BanglaLegalNER" # Ensure this model is suitable or update accordingly
|
9 |
+
tokenizer_name = "csebuetnlp/banglat5_banglaparaphrase"
|
10 |
+
|
11 |
+
# Load the tokenizer and model
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, use_fast=False)
|
13 |
+
model = AutoModelForTokenClassification.from_pretrained(model_name)
|
14 |
+
|
15 |
+
def merge_tokens(tokens: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
16 |
merged_tokens = []
|
17 |
for token in tokens:
|
18 |
if merged_tokens and token['entity'].startswith('I-') and merged_tokens[-1]['entity'].endswith(token['entity'][2:]):
|
|
|
27 |
# Determine device
|
28 |
device = 0 if torch.cuda.is_available() else -1
|
29 |
|
30 |
+
# Initialize Pipeline with the new model and tokenizer
|
31 |
+
get_completion = pipeline("ner", model=model, tokenizer=tokenizer, device=device)
|
32 |
|
33 |
@spaces.GPU(duration=120)
|
34 |
def ner(input: str) -> Dict[str, Any]:
|
|
|
43 |
title = """<h1 id="title"> Bangla Legal Entity Recognition </h1>"""
|
44 |
|
45 |
description = """
|
46 |
+
- The model used for Recognizing entities [Bangla Legal NER](https://huggingface.co/kazalbrur/BanglaLegalNER).
|
47 |
"""
|
48 |
|
49 |
css = '''
|