svjack commited on
Commit
34d4913
1 Parent(s): ec67560

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from predict import *
2
+ from transformers import BloomTokenizerFast, BloomForCausalLM
3
+
4
+ import os
5
+ import gradio as gr
6
+
7
+ model_path = "svjack/bloom-dialogue"
8
+ tokenizer = BloomTokenizerFast.from_pretrained(model_path)
9
+ model = BloomForCausalLM.from_pretrained(model_path)
10
+
11
+ obj = Obj(model, tokenizer)
12
+
13
+ example_sample = [
14
+ ["今天天气不错。", 128],
15
+ ["你饿吗?", 128],
16
+ ]
17
+
18
+ def demo_func(prefix, max_length):
19
+ max_length = max(int(max_length), 32)
20
+ l = obj.predict(prefix, max_length=max_length)[0].split("\n-----\n")
21
+ l_ = []
22
+ for ele in l:
23
+ if ele not in l_:
24
+ l_.append(ele)
25
+ l = l_
26
+ assert type(l) == type([])
27
+ return {
28
+ "Dialogue Context": l
29
+ }
30
+
31
+ demo = gr.Interface(
32
+ fn=demo_func,
33
+ inputs=[gr.Text(label = "Prefix"),
34
+ gr.Number(label = "Max Length", value = 128)
35
+ ],
36
+ outputs="json",
37
+ title=f"Bloom Chinese Dialogue Generator 🐰🌸 demonstration",
38
+ examples=example_sample if example_sample else None,
39
+ description = 'This _example_ was **drive** from <br/><b><h4>[https://github.com/svjack/Daliy-Dialogue](https://github.com/svjack/Daliy-Dialogue)</h4></b>\n',
40
+ cache_examples = False
41
+ )
42
+
43
+ demo.launch(server_name=None, server_port=None)