Spaces:
Running
Running
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 。 |