yf12 commited on
Commit
7b08850
·
1 Parent(s): d8cfa37

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
+
5
+ generator = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B')
6
+
7
+ def get_msg(prompt):
8
+ res = generator(prompt, max_length=50, do_sample=True, temperature=0.9)
9
+ message = res[0]['generated_text']
10
+ return message.strip()
11
+
12
+ def chatbot(input, history=[]):
13
+ output = get_msg(input)
14
+ history.append((input, output))
15
+ return history, history
16
+
17
+ gr.Interface(fn = chatbot,
18
+ inputs = ["text",'state'],
19
+ outputs = ["chatbot",'state']).queue(concurrency_count=1,max_size=1).launch()