kaiku03 commited on
Commit
aa957fe
1 Parent(s): 77624d2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Initialize the pipeline once
5
+ mask_filler = pipeline(
6
+ "fill-mask",
7
+ model="kaiku03/MLM-distilbert-base-uncased-finetuned-game_titles_accelerate"
8
+ )
9
+
10
+ def fill_mask(prompt):
11
+ output = mask_filler(prompt)
12
+
13
+ # Extract the top 3 sequences and their scores
14
+ top_sequences = {i['sequence']: i['score'] for i in output[:10]}
15
+
16
+ # Return the dictionary
17
+ return top_sequences
18
+
19
+
20
+ # gradio app
21
+ # Define example inputs and outputs
22
+ examples = [
23
+ "league of [MASK].",
24
+ "[MASK] Raider",
25
+ "Grand [MASK] Auto ",
26
+ ]
27
+
28
+ iface = gr.Interface(
29
+ fn=fill_mask,
30
+ inputs='text',
31
+ outputs=gr.Label(num_top_classes=4, label="Predictions"),
32
+ examples=[
33
+ [ex] for ex in examples
34
+ ],
35
+ title='Game Titles Prediction',
36
+ description='This demo performs auto-completion of game titles based on surrounding text.',
37
+ article='All done by Kaiku, documentation at https://medium.com/p/b09b45dd7ce8/edit',
38
+
39
+ )
40
+
41
+ iface.launch()
42
+