dar-tau commited on
Commit
94466d1
·
verified ·
1 Parent(s): e846748

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -22,6 +22,22 @@ Propose auto-completion to the text. You have several roles:
22
  Don't suggest anything if there are no good suggestions.
23
  Make sure the suggestions are valid completions of the text! Suggest only up to 5 words ahead. The scheme of your answer should be "answer1;answer2;answer3" (return between 0 to 4 answers).
24
  Answers should be only the completions themselves.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  You will now get a blank message from the user and then after your answer, the user will give you the text to complete:
26
  Example:
27
 
@@ -50,8 +66,8 @@ Assistant: "girlfriend;mother;father;friend"
50
 
51
  start_messages = [
52
  {'role': 'system', 'content': system_prompt},
53
- {'role': 'user', 'content': ' '},
54
- {'role': 'assistant', 'content': '<Waiting for text>'}
55
  ]
56
 
57
 
@@ -88,7 +104,9 @@ def generate(text, past_key_values):
88
  *start_messages,
89
  {'role': 'user', 'content': text}
90
  ]
91
- past_key_values = past_kv_to_device(past_key_values, pipe.model.device, pipe.model.dtype)
 
 
92
  response = pipe(messages,
93
  past_key_values=past_key_values,
94
  **generate_kwargs)[0]['generated_text']
@@ -97,8 +115,8 @@ def generate(text, past_key_values):
97
 
98
  if __name__ == "__main__":
99
  with torch.no_grad():
100
- past_key_values = set_past_key_values()
101
- print(f'{past_key_values=}')
102
- demo = gr.Interface(partial(generate, past_key_values=past_key_values),
103
  inputs="textbox", outputs="textbox")
104
  demo.launch()
 
22
  Don't suggest anything if there are no good suggestions.
23
  Make sure the suggestions are valid completions of the text! Suggest only up to 5 words ahead. The scheme of your answer should be "answer1;answer2;answer3" (return between 0 to 4 answers).
24
  Answers should be only the completions themselves.
25
+ Examples:
26
+ (1)
27
+ User: "Help me write a sentiment analysis pipeline"
28
+ Assistant: "using huggingface;using NLTK;using python"
29
+
30
+ (2)
31
+ User: "My name is"
32
+ Assistant: "" (nothing much to contribute at this point. return nothing)
33
+
34
+ (3)
35
+ User: "Help me find a present for my"
36
+ Assistant: "girlfriend;mother;father;friend"
37
+
38
+ '''
39
+
40
+ '''
41
  You will now get a blank message from the user and then after your answer, the user will give you the text to complete:
42
  Example:
43
 
 
66
 
67
  start_messages = [
68
  {'role': 'system', 'content': system_prompt},
69
+ # {'role': 'user', 'content': ' '},
70
+ # {'role': 'assistant', 'content': '<Waiting for text>'}
71
  ]
72
 
73
 
 
104
  *start_messages,
105
  {'role': 'user', 'content': text}
106
  ]
107
+
108
+ if past_key_values:
109
+ past_key_values = past_kv_to_device(past_key_values, pipe.model.device, pipe.model.dtype)
110
  response = pipe(messages,
111
  past_key_values=past_key_values,
112
  **generate_kwargs)[0]['generated_text']
 
115
 
116
  if __name__ == "__main__":
117
  with torch.no_grad():
118
+ # past_key_values = set_past_key_values()
119
+ # print(f'{past_key_values=}')
120
+ demo = gr.Interface(partial(generate, past_key_values=None),
121
  inputs="textbox", outputs="textbox")
122
  demo.launch()