File size: 858 Bytes
8ce9d45
164d84e
8ec0ee1
 
1969211
 
 
 
 
70fe0b3
9e66c5d
1969211
 
53e33e7
1969211
3cb51d0
41d275a
f817f7e
 
15b7d4b
55181fa
15b7d4b
 
0e725b3
15b7d4b
 
 
1969211
 
9e66c5d
1969211
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
import gradio as gr
import random
from transformers import pipeline

fill_mask = pipeline(
    "fill-mask",
    model="alger-ia/dziribert",
    tokenizer="alger-ia/dziribert"
)

def greet(prompt="أنا", maxTokens=50):
    generated_text_set = set()
    text = prompt +" [MASK]"
    for i in range(int(maxTokens)):
        result = fill_mask(text)
        print(text)
        print(result)
        print(result[0])
        print(result[0][0]['sequence'])
        if result:
            r = random.choice(result[0])['sequence']
            if r not in generated_text_set:
                print(r)
                text = r+ " [MASK]"
                generated_text_set.add(r)
            else:
                continue
    return text

iface = gr.Interface(fn=greet, inputs=["text", "number"], outputs="text", examples=[["أنا [MASK]",50]] )
iface.launch()