arjunpatel commited on
Commit
658b022
1 Parent(s): 91a9511

skeleton version of demo working

Browse files
Files changed (1) hide show
  1. gradio_demo.py +60 -0
gradio_demo.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer
3
+ from transformers import pipeline
4
+
5
+ model_checkpoint = "distilgpt2"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
8
+
9
+ generate = pipeline("text-generation",
10
+ model="arjunpatel/distilgpt2-finetuned-pokemon-moves",
11
+ tokenizer=tokenizer)
12
+
13
+
14
+ def filter_text(generated_move):
15
+ # removes any moves that follow after the genrated move
16
+ print(generated_move)
17
+ sentences = generated_move.split(".")
18
+ if len(sentences) > 2:
19
+ ret_set = " ".join(sentences[0:1])
20
+ else:
21
+ ret_set = generated_move
22
+ return ret_set
23
+
24
+ def create_move(move):
25
+ seed_text = "This move is called "
26
+ generated_move = generate(seed_text + move, num_return_sequences=2,
27
+ no_repeat_ngram_size=4)[0]["generated_text"]
28
+ return generated_move
29
+
30
+
31
+ # # demo = gr.Interface(fn=greet, inputs = "text", outputs="text")
32
+ #
33
+ # gr.Interface(fn=create_move,
34
+ # inputs="text", outputs="text").launch()
35
+ # # demo.launch()
36
+
37
+ def filler_move(test_move, temperature):
38
+ return test_move + " with temperature " + str(temperature)
39
+
40
+ demo = gr.Blocks()
41
+
42
+ with demo:
43
+ gr.Markdown("What's that Pokemon Move?")
44
+ with gr.Tabs():
45
+ with gr.TabItem("Standard Generation"):
46
+ with gr.Row():
47
+ text_input_baseline = gr.Textbox()
48
+ text_output_baseline = gr.Textbox()
49
+ text_button_baseline = gr.Button("Create my move!")
50
+ with gr.TabItem("Temperature Search"):
51
+ with gr.Row():
52
+ temperature = gr.Slider(minimum = 0.3, maximum = 4, value = 1, step = 0.1,
53
+ label = "Temperature")
54
+ text_input_temp = gr.Textbox(label="Move Name")
55
+ text_output_temp = gr.Textbox(label = "Move Description")
56
+ text_button_temp = gr.Button("Create my move!")
57
+
58
+ #text_button_baseline.click(filler_move, inputs=[text_input_baseline, 0], outputs=text_output_baseline)
59
+ text_button_temp.click(filler_move, inputs=[text_input_temp, temperature], outputs=text_output_temp)
60
+ demo.launch()