StKirill commited on
Commit
30b222a
·
verified ·
1 Parent(s): d0c3756

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer
2
+ from transformers import pipeline
3
+ from transformers import TextDataset, DataCollatorForLanguageModeling
4
+ from transformers import Trainer, TrainingArguments,AutoModelWithLMHead
5
+
6
+ chef = pipeline('text-generation', model="./models/en_gpt2-medium_rachel_replics", tokenizer=model_type)
7
+ tmp = chef(f"<s>NOTFRIEND: Do you like Ross?\nRACHEL:")[0]['generated_text']
8
+ tmp = tmp[tmp.find(f"RACHEL: ") + len("RACHEL") + 2 : tmp.find('</s>')]
9
+ tmp
10
+
11
+ # gradio part
12
+ def echo(message, history, model):
13
+
14
+ chef = pipeline('text-generation', model="./models/en_gpt2-medium_rachel_replics", tokenizer=model_type)
15
+
16
+ if model=="gpt2-medium":
17
+ answer = chef(f"<s>NOTFRIEND: {message}}\nRACHEL:")[0]['generated_text']
18
+ answer = tmp[tmp.find(f"RACHEL: ") + len("RACHEL") + 2 : tmp.find('</s>')]
19
+ return answer
20
+
21
+ elif model=="gpt2-medium":
22
+ answer = chef(f"<s>NOTFRIEND: {message}}\nRACHEL:")[0]['generated_text']
23
+ answer = tmp[tmp.find(f"RACHEL: ") + len("RACHEL") + 2 : tmp.find('</s>')]
24
+ return answer
25
+
26
+ elif model=="gpt2-medium":
27
+ answer = chef(f"<s>NOTFRIEND: {message}}\nRACHEL:")[0]['generated_text']
28
+ answer = tmp[tmp.find(f"RACHEL: ") + len("RACHEL") + 2 : tmp.find('</s>')]
29
+ return answer
30
+
31
+
32
+
33
+
34
+ title = "Chatbot who speaks like Rachel from Friends"
35
+ description = "You have a good opportunity to have a dialog with actress from Friends - Rachel Green"
36
+
37
+ model = gr.Dropdown(["gpt2", "gpt2-medium", "gpt2-large"], label="LLM", info="What model do you want to use?", value="gpt2-medium")
38
+
39
+ with gr.Blocks() as demo:
40
+
41
+ gr.ChatInterface(
42
+ fn=echo,
43
+ title=title,
44
+ description=description,
45
+ additional_inputs=[model],
46
+ retry_btn=None,
47
+ undo_btn=None,
48
+ clear_btn=None,
49
+ )
50
+
51
+ demo.launch(debug=False, share=True)