Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-daliy-dialogue-english"
|
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 |
+
["This dog is fierce,", 128],
|
15 |
+
["Do you like this film?", 64],
|
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 English Daliy Dialogue Generator 🦅🌸 demonstration",
|
38 |
+
examples=example_sample if example_sample else None,
|
39 |
+
cache_examples = False
|
40 |
+
)
|
41 |
+
|
42 |
+
demo.launch(server_name=None, server_port=None)
|