Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import random
|
|
4 |
|
5 |
generator = pipeline('text-generation', model='jslin09/bloom-560m-finetuned-fraud')
|
6 |
|
7 |
-
def
|
8 |
rnd_seed = random.randint(10, 500)
|
9 |
set_seed(rnd_seed)
|
10 |
result = generator(text,
|
@@ -16,6 +16,18 @@ def generate(text):
|
|
16 |
top_p=0.9)
|
17 |
return result[0]["generated_text"]
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
examples = [
|
20 |
["闕很大明知金融帳戶之存摺、提款卡及密碼係供自己使用之重要理財工具,"],
|
21 |
["森上梅前明知其無資力支付酒店消費,亦無付款意願,竟意圖為自己不法之所有,"],
|
@@ -30,11 +42,13 @@ with gr.Blocks() as demo:
|
|
30 |
with gr.Row():
|
31 |
with gr.Column():
|
32 |
prompt = gr.components.Textbox(lines=5, label="輸入提示文字", placeholder=examples[0])
|
33 |
-
btn = gr.Button("
|
|
|
34 |
gr.Examples(examples, inputs=[prompt])
|
35 |
with gr.Column():
|
36 |
result = gr.components.Textbox(lines=15, label="生成的草稿")
|
37 |
-
btn.click(
|
|
|
38 |
|
39 |
if __name__ == "__main__":
|
40 |
demo.launch() # 在遠端啟動時,需要 share=True 。
|
|
|
4 |
|
5 |
generator = pipeline('text-generation', model='jslin09/bloom-560m-finetuned-fraud')
|
6 |
|
7 |
+
def rnd_generate(text):
|
8 |
rnd_seed = random.randint(10, 500)
|
9 |
set_seed(rnd_seed)
|
10 |
result = generator(text,
|
|
|
16 |
top_p=0.9)
|
17 |
return result[0]["generated_text"]
|
18 |
|
19 |
+
def generate(text):
|
20 |
+
set_seed(46)
|
21 |
+
result = generator(text,
|
22 |
+
max_length=500,
|
23 |
+
num_return_sequences=1,
|
24 |
+
do_sample=True,
|
25 |
+
temperature=0.75,
|
26 |
+
top_k=50,
|
27 |
+
top_p=0.9)
|
28 |
+
return result[0]["generated_text"]
|
29 |
+
|
30 |
+
|
31 |
examples = [
|
32 |
["闕很大明知金融帳戶之存摺、提款卡及密碼係供自己使用之重要理財工具,"],
|
33 |
["森上梅前明知其無資力支付酒店消費,亦無付款意願,竟意圖為自己不法之所有,"],
|
|
|
42 |
with gr.Row():
|
43 |
with gr.Column():
|
44 |
prompt = gr.components.Textbox(lines=5, label="輸入提示文字", placeholder=examples[0])
|
45 |
+
btn = gr.Button("隨機生成草稿")
|
46 |
+
btn2 = gr.Button("固定生成草稿")
|
47 |
gr.Examples(examples, inputs=[prompt])
|
48 |
with gr.Column():
|
49 |
result = gr.components.Textbox(lines=15, label="生成的草稿")
|
50 |
+
btn.click(rnd_generate, inputs=[prompt], outputs=[result])
|
51 |
+
btn2.click(generate, inputs=[prompt], outputs=[result])
|
52 |
|
53 |
if __name__ == "__main__":
|
54 |
demo.launch() # 在遠端啟動時,需要 share=True 。
|