File size: 2,119 Bytes
32b0450
d97db75
528c89f
7fc842c
61505d3
7fc842c
1616f44
28f307c
 
2ace237
 
 
 
 
 
 
351b9e5
 
1616f44
bd870f4
1616f44
 
 
 
 
 
 
 
 
 
351b9e5
081ad0c
44f8057
bd870f4
 
7fc842c
 
28f307c
 
 
48e0bd2
28f307c
 
 
9e7050b
5dc06b4
 
9e7050b
5dc06b4
9e7050b
28f307c
 
9e7050b
1616f44
 
7fc842c
8c28f7d
28f307c
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
import gradio as gr
from transformers import pipeline, set_seed
import random

generator = pipeline('text-generation', model='jslin09/bloom-560m-finetuned-fraud')

def rnd_generate(text):
    rnd_seed = random.randint(10, 500)
    set_seed(rnd_seed)
    result = generator(text,
                       max_length=500,
                       num_return_sequences=1,
                       do_sample=True,
                       temperature=0.75,
                       top_k=50, 
                       top_p=0.9)
    return result[0]["generated_text"]

def generate(text):
    set_seed(55)
    result = generator(text,
                       max_length=500,
                       num_return_sequences=1,
                       do_sample=True,
                       temperature=0.75,
                       top_k=50, 
                       top_p=0.9)
    return result[0]["generated_text"]


examples = [
    ["闕很大明知金融帳戶之存摺、提款卡及密碼係供自己使用之重要理財工具,"],
    ["森上梅前明知其無資力支付酒店消費,亦無付款意願,竟意圖為自己不法之所有,"],
    ["王大明意圖為自己不法所有,基於竊盜之犯意,"],
    ["假住院病患企圖住院以詐領保險住院理賠金"]
]

with gr.Blocks() as demo:
    gr.Markdown(
    """
    <h1 style="text-align: center;">Legal Document Drafting</h1>
    """)
    with gr.Row():
        with gr.Column():
            prompt = gr.components.Textbox(lines=5, label="Input Prompt", placeholder=examples[0])
            with gr.Row():
                with gr.Column():
                    btn = gr.Button("Random Drafting")
                with gr.Column():
                    btn2 = gr.Button("Drafting")
            gr.Examples(examples, inputs=[prompt])
        with gr.Column():    
            result = gr.components.Textbox(lines=15, label="Generative")
        btn.click(rnd_generate, inputs=[prompt], outputs=[result])
        btn2.click(generate, inputs=[prompt], outputs=[result])

if __name__ == "__main__":
    demo.launch() # 在遠端啟動時,需要 share=True 。