Hann99 commited on
Commit
572f4d0
1 Parent(s): 47b6faf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -46
app.py CHANGED
@@ -1,46 +1,31 @@
1
- from transformers import AutoModelForCausalLM, AutoTokenizer,BlenderbotForConditionalGeneration
2
- import torch
3
- chat_tkn = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
4
- mdl = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
5
- #chat_tkn = AutoTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
6
- #mdl = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill")
7
- def converse(user_input, chat_history=[]):
8
- user_input_ids = chat_tkn(user_input + chat_tkn.eos_token, return_tensors='pt').input_ids
9
- # keep history in the tensor
10
- bot_input_ids = torch.cat([torch.LongTensor(chat_history), user_input_ids], dim=-1)
11
- # get response
12
- chat_history = mdl.generate(bot_input_ids, max_length=1000, pad_token_id=chat_tkn.eos_token_id).tolist()
13
- print (chat_history)
14
- response = chat_tkn.decode(chat_history[0]).split("<|endoftext|>")
15
- print("starting to print response")
16
- print(response)
17
- # html for display
18
- html = "<div class='mybot'>"
19
- for x, mesg in enumerate(response):
20
- if x%2!=0 :
21
- mesg="Alicia:"+mesg
22
- clazz="alicia"
23
- else :
24
- clazz="user"
25
- print("value of x")
26
- print(x)
27
- print("message")
28
- print (mesg)
29
- html += "<div class='mesg {}'> {}</div>".format(clazz, mesg)
30
- html += "</div>"
31
- print(html)
32
- return html, chat_history
33
- import gradio as grad
34
- css = """
35
- .mychat {display:flex;flex-direction:column}
36
- .mesg {padding:5px;margin-bottom:5px;border-radius:5px;width:75%}
37
- .mesg.user {background-color:lightblue;color:white}
38
- .mesg.alicia {background-color:orange;color:white,align-self:self-end}
39
- .footer {display:none !important}
40
- """
41
- text=grad.inputs.Textbox(placeholder="Lets chat")
42
- grad.Interface(fn=converse,
43
- theme="default",
44
- inputs=[text, "state"],
45
- outputs=["html", "state"],
46
- css=css).launch()
 
1
+ import gradio as gr
2
+ import 期刊论文投稿推荐系统
3
+ textbox_keyword_inputs = gr.inputs.Textbox(lines=6, placeholder='关键词', default='', label=None, optional=False)
4
+ textbox_abstract = gr.inputs.Textbox(lines=1, placeholder='请输入文章摘要', default='', label='摘要', optional=False)
5
+
6
+
7
+ def greet(textbox_keyword_inputs, history=[]):
8
+ outputs = 期刊论文投稿推荐系统.extract_tags(textbox_keyword_inputs)
9
+ label = outputs[0]
10
+ values_1 = outputs[1]
11
+ history.append(textbox_keyword_inputs)
12
+ print([(f"{history[len(history)-1]}", f"{label[0]}")])
13
+ print('----------------------------------')
14
+ print(textbox_keyword_inputs)
15
+ # return [(f"{history[0]}",f"{gr.HTML('根据您的论文所推荐的期刊.html')}")], history
16
+ return [(f"{history[len(history)-1][:50]+'.....'}", f"{label[0]+'综合影响因子:'+str(values_1[0])}")], history
17
+
18
+
19
+ with gr.Blocks() as Interface:
20
+ # 实例化一个机器人聊天组件
21
+ chatbot = gr.Chatbot()
22
+ # 状态码
23
+ state = gr.State([])
24
+ # 水平居中排列
25
+ with gr.Row():
26
+ # 实例化输入文本框
27
+ txt = gr.Textbox(show_label=False, placeholder="请输入文章摘要").style(container=False)
28
+ # 提交文本框后执行分析并输出
29
+ txt.submit(greet, [txt, state], [chatbot, state])
30
+ if __name__ == "__main__":
31
+ Interface.launch()