File size: 2,241 Bytes
a2ecef0
 
 
 
 
34d4913
 
 
a2ecef0
34d4913
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a2ecef0
 
 
 
 
 
 
 
 
 
34d4913
 
 
 
 
 
 
 
90d3c1c
 
34d4913
 
 
90d3c1c
 
 
 
 
 
 
 
 
 
 
 
 
 
34d4913
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os 
os.system("pip install huggingface_hub")

from huggingface_hub import space_info

from predict import *
from transformers import BloomTokenizerFast, BloomForCausalLM

#import os
import gradio as gr

model_path = "svjack/bloom-dialogue"
tokenizer = BloomTokenizerFast.from_pretrained(model_path)
model = BloomForCausalLM.from_pretrained(model_path)

obj = Obj(model, tokenizer)

example_sample = [
    ["今天天气不错。", 128],
    ["你饿吗?", 128],
]

def demo_func(prefix, max_length):
    max_length = max(int(max_length), 32)
    l = obj.predict(prefix, max_length=max_length)[0].split("\n-----\n")
    l_ = []
    for ele in l:
        if ele not in l_:
            l_.append(ele)
    l = l_
    assert type(l) == type([])
    return {
        "Dialogue Context": l
    }

markdown_exp_size = "##"
lora_repo = "svjack/chatglm3-few-shot"
lora_repo_link = "svjack/chatglm3-few-shot/?input_list_index=10"
emoji_info = space_info(lora_repo).__dict__["cardData"]["emoji"]
space_cnt = 1
task_name = "[---Chinese Dialogue Generator---]"
description = f"{markdown_exp_size} {task_name} few shot prompt in ChatGLM3 Few Shot space repo (click submit to activate) : [{lora_repo_link}](https://huggingface.co/spaces/{lora_repo_link}) {emoji_info}"



demo = gr.Interface(
        fn=demo_func,
        inputs=[gr.Text(label = "Prefix"),
                gr.Number(label = "Max Length", value = 128)
        ],
        outputs="json",
        title=f"Bloom Chinese Dialogue Generator 🐰🌸 demonstration",
        examples=example_sample if example_sample else None,
        description = 'This _example_ was **drive** from <br/><b><h4>[https://github.com/svjack/Daliy-Dialogue](https://github.com/svjack/Daliy-Dialogue)</h4></b>\n',
        #description = description,
        cache_examples = False
    )

with demo:
    gr.HTML(
    '''
                <div style="justify-content: center; display: flex;">
                <iframe
                src="https://svjack-chatglm3-few-shot-demo.hf.space/?input_list_index=10"
                frameborder="0"
                width="1400"
                height="768"
                ></iframe>
                </div>
    '''
    )

demo.launch(server_name=None, server_port=None)