Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import os
|
2 |
-
from typing import Optional
|
3 |
from functools import partial
|
4 |
import gradio as gr
|
5 |
import spaces
|
@@ -53,7 +53,7 @@ start_messages = [
|
|
53 |
# functions
|
54 |
@dataclass
|
55 |
class PastKV:
|
56 |
-
past_key_values:
|
57 |
|
58 |
past_key_values = PastKV()
|
59 |
|
@@ -82,7 +82,7 @@ def generate(text, past_key_values):
|
|
82 |
{'role': 'user', 'content': text}
|
83 |
]
|
84 |
response = pipe(messages,
|
85 |
-
past_key_values=past_key_values, #past_kv_to_device(past_key_values, pipe.model.device),
|
86 |
**generate_kwargs)[0]['generated_text']
|
87 |
return response[-1]['content']
|
88 |
|
@@ -90,6 +90,7 @@ def generate(text, past_key_values):
|
|
90 |
if __name__ == "__main__":
|
91 |
with torch.no_grad():
|
92 |
set_past_key_values()
|
93 |
-
|
|
|
94 |
inputs="textbox", outputs="textbox")
|
95 |
demo.launch()
|
|
|
1 |
import os
|
2 |
+
from typing import Optional, Tuple, Any
|
3 |
from functools import partial
|
4 |
import gradio as gr
|
5 |
import spaces
|
|
|
53 |
# functions
|
54 |
@dataclass
|
55 |
class PastKV:
|
56 |
+
past_key_values: Any = None
|
57 |
|
58 |
past_key_values = PastKV()
|
59 |
|
|
|
82 |
{'role': 'user', 'content': text}
|
83 |
]
|
84 |
response = pipe(messages,
|
85 |
+
past_key_values=past_key_values.past_key_values, #past_kv_to_device(past_key_values, pipe.model.device),
|
86 |
**generate_kwargs)[0]['generated_text']
|
87 |
return response[-1]['content']
|
88 |
|
|
|
90 |
if __name__ == "__main__":
|
91 |
with torch.no_grad():
|
92 |
set_past_key_values()
|
93 |
+
print(past_key_values)
|
94 |
+
demo = gr.Interface(partial(generate),
|
95 |
inputs="textbox", outputs="textbox")
|
96 |
demo.launch()
|