Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ from PIL import Image
|
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
| 5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 6 |
-
from huggingface_hub.inference._generated.types import TextGenerationStreamOutput, TextGenerationStreamOutputToken
|
| 7 |
import os
|
| 8 |
from threading import Thread
|
| 9 |
|
|
@@ -64,17 +63,11 @@ def stream_chat(message: str, history: list, temperature: float, max_length: int
|
|
| 64 |
with torch.no_grad():
|
| 65 |
thread = Thread(target=model.generate, kwargs=gen_kwargs)
|
| 66 |
thread.start()
|
| 67 |
-
for
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
logprob=0,
|
| 73 |
-
text=next_text,
|
| 74 |
-
special=False,
|
| 75 |
-
)
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
|
| 79 |
|
| 80 |
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
| 5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
|
|
|
| 6 |
import os
|
| 7 |
from threading import Thread
|
| 8 |
|
|
|
|
| 63 |
with torch.no_grad():
|
| 64 |
thread = Thread(target=model.generate, kwargs=gen_kwargs)
|
| 65 |
thread.start()
|
| 66 |
+
for new_token in streamer:
|
| 67 |
+
if new_token:
|
| 68 |
+
history[-1][1] += new_token
|
| 69 |
+
yield history
|
| 70 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
|