jslin09 commited on
Commit
7fc842c
1 Parent(s): 02897df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -32
app.py CHANGED
@@ -1,33 +1,40 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
3
- import torch
4
-
5
- tokenizer = AutoTokenizer.from_pretrained("jslin09/bloom-560m-finetuned-fraud")
6
- model = AutoModelForCausalLM.from_pretrained("jslin09/bloom-560m-finetuned-fraud")
7
-
8
- def predict(input, history=[]):
9
- # tokenize the new input sentence
10
- new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
11
-
12
- # append the new user input tokens to the chat history
13
- bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
14
-
15
- # generate a response
16
- history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
17
-
18
- # convert the tokens to text, and then split the responses into lines
19
- response = tokenizer.decode(history[0]).split("<|endoftext|>")
20
- response = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)] # convert to tuples of list
21
- return response, history
22
-
23
- with gr.Blocks() as demo:
24
- chatbot = gr.Chatbot()
25
- state = gr.State([])
26
-
27
- with gr.Row():
28
- txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(container=False)
29
-
30
- txt.submit(predict, [txt, state], [chatbot, state])
31
-
32
- if __name__ == "__main__":
33
- demo.launch()
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ #pipe = pipeline("text-generation")
5
+ #gr.Interface.from_pipeline(pipe).launch()
6
+
7
+ API_URL = "https://api-inference.huggingface.co/models/jslin09/bloom-560m-finetuned-fraud"
8
+ headers = {"Authorization": "Bearer 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"} # Read only
9
+
10
+ description = "Legal Document Drafting with BLOOM"
11
+ api_key="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"
12
+ examples=[
13
+ ["闕很大明知金融帳戶之存摺、提款卡及密碼係供自己使用之重要理財工具,"],
14
+ ["森上梅前明知其無資力支付酒店消費,亦無付款意願,竟意圖為自己不法之所有,"]
15
+ ]
16
+
17
+ iface = gr.Interface.load(
18
+ "huggingface/jslin09/bloom-560m-finetuned-fraud",
19
+ title="Drafting",
20
+ inputs=[
21
+ gr.Textbox(lines=10, label="Prompt", value="闕很大明知金融帳戶之存摺、提款卡及密碼係供自己使用之重要理財工具,"), # prompt
22
+ gr.Slider(10, 200, step=10, value=100), # token_count
23
+ gr.Slider(0.2, 2.0, step=0.1, value=1.0), # temperature
24
+ gr.Slider(0.0, 1.0, step=0.05, value=0.8), # top_p
25
+ gr.Slider(0.0, 1.0, step=0.1, value=0.1), # presencePenalty
26
+ gr.Slider(0.0, 1.0, step=0.1, value=0.1), # countPenalty
27
+ ],
28
+ outputs=gr.Textbox(label="生成的草稿", lines=28),
29
+ description=description,
30
+ examples=examples,
31
+ api_key=api_key,
32
+ ).queue()
33
+
34
+ demo = gr.TabbedInterface(
35
+ [iface], ["分頁標籤"],
36
+ title="Legal Document Drafting",
37
+ )
38
+
39
+ demo.queue()
40
+ demo.launch(share=False)