File size: 3,055 Bytes
d153804
1456d3c
907b7bf
5e7a6e2
1456d3c
 
 
cebb97f
1456d3c
 
 
5e7a6e2
1456d3c
 
 
d592d52
 
d153804
5e7a6e2
 
 
d153804
 
adf733e
d153804
 
adf733e
7ded172
 
 
 
 
 
 
d153804
 
 
 
 
 
 
 
 
5539f17
d153804
 
61cf48b
d153804
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""import gradio as gr
from simpletransformers.ner import NERModel 
import string


model = NERModel(
        "albert",  #roberta
        "bgk/lodosalberttr", ignore_mismatched_sizes=True,
        use_cuda=False
    )
def ner(text, model):
    trans_table = text.maketrans('', '', string.punctuation)
    text = " ".join(text.translate(trans_table).split())
    text = text.lower()
    prediction, model_output = model.predict([text])
    output = prediction
    return output

demo = gr.Interface(fn=ner, inputs=gr.Textbox(lines=5, placeholder='Enter your input here'), outputs=gr.Textbox(lines=10, placeholder='Sipariş dökümü'),examples=['İki pide ve iki büyük ayran istiyorum, kapıda nakit öderim, evime yollayın...' , 'Bir mantı, iki döner, üç mevsim salata, bir kola ve iki sprite istiyorum, iş yerime gönderin' ],
    title="Söyle Gelsin", description="Yemek siparişi uygulamamızı kullanabilirsiniz...")

demo.launch()
"""
import gradio as gr
from simpletransformers.ner import NERModel 
import string

labels = ["B-YEMEK","O","B-ICECEK_BUYUKLUK","B-ICECEK","B-ADRES","B-ODEME","B-YEMEK_CESIT","B-YEMEK_ADET","B-ICECEK_ICERIK","I-ADRES","I-YEMEK","B-YEMEK_BUYUKLUK","B-YEMEK_ICERIK","I-YEMEK_ICERIK","I-ICECEK","I-YEMEK_BUYUKLUK","I-YEMEK_CESIT","B-ICECEK_ADET","I-ODEME","I-YEMEK_ADET"]
model = NERModel(
        "albert", 
        "bgk/lodosalberttr", labels=labels,
        use_cuda=False,
        ignore_mismatched_sizes=True
    )

def ner(text):
    trans_table = text.maketrans('', '', string.punctuation)
    text = text.translate(trans_table)

    text=text.lower()
    
    prediction, model_output = model.predict([text])
    filtered_output = [[{v: k} for d in sublist for k, v in d.items() if v.startswith("B-")] for sublist in prediction]
    entities = prediction
    return entities

demo = gr.Interface(fn=ner, inputs=gr.Textbox(lines=5, placeholder='Enter your input here'), outputs=gr.Textbox(lines=5, placeholder='Sipariş dökümü'),examples=['Bize iki buçuk pide ve iki büyük ayran istiyorum, kapıda nakit öderim, evime yollayın...' , 'bir mantı, bir döner, iki salata, bir kola ve bir sprite istiyorum', 'bana adana kebap iki adet, yanına bir kola ve ayran ver bir tane' ],
    title="Söyle Gelsin", description="Yemek siparişi uygulamamızı kullanabilirsiniz...")

demo.launch()
""" 
model = NERModel(
        "albert", 
        "bgk/lodosalberttr", ignore_mismatched_sizes=True,
        use_cuda=False
    )

examples = [
    ["İki pide ve iki büyük ayran istiyorum, kapıda nakit öderim, evime yollayın"],
    ["Bir mantı, iki döner, üç mevsim salata, bir kola ve iki sprite istiyorum, iş yerime gönderin"],
    ["bana adana kebap iki adet, yanına bir kola ve ayran ver bir tane"]
            
]

    
def ner(text):
    output = ner_pipeline(text)
    return {"text": text, "entities": output}    

demo = gr.Interface(ner,
             gr.Textbox(placeholder="Inserisci una frase qui..."), 
             gr.HighlightedText(),
             examples=examples)

demo.launch()
"""