Spaces:
Sleeping
Sleeping
Update src/chatbot.py
Browse files- src/chatbot.py +3 -4
src/chatbot.py
CHANGED
|
@@ -17,20 +17,19 @@ logger = logging.getLogger(__name__)
|
|
| 17 |
from langchain.callbacks.base import BaseCallbackHandler
|
| 18 |
|
| 19 |
class StreamHandler(BaseCallbackHandler):
|
| 20 |
-
def __init__(self, placeholder):
|
| 21 |
self.current_text = ""
|
| 22 |
self.placeholder = placeholder
|
| 23 |
|
| 24 |
def on_llm_new_token(self, token: str, **kwargs):
|
| 25 |
self.current_text += token
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
def get_text(self):
|
| 30 |
return self.current_text
|
| 31 |
|
| 32 |
|
| 33 |
-
|
| 34 |
class BioethicsChatbot:
|
| 35 |
def __init__(self, data_dir: str="data/sample_papers"):
|
| 36 |
self.processor = DocumentProcessor()
|
|
|
|
| 17 |
from langchain.callbacks.base import BaseCallbackHandler
|
| 18 |
|
| 19 |
class StreamHandler(BaseCallbackHandler):
|
| 20 |
+
def __init__(self, placeholder=None):
|
| 21 |
self.current_text = ""
|
| 22 |
self.placeholder = placeholder
|
| 23 |
|
| 24 |
def on_llm_new_token(self, token: str, **kwargs):
|
| 25 |
self.current_text += token
|
| 26 |
+
if self.placeholder:
|
| 27 |
+
self.placeholder.markdown(self.current_text + "▌")
|
| 28 |
|
| 29 |
def get_text(self):
|
| 30 |
return self.current_text
|
| 31 |
|
| 32 |
|
|
|
|
| 33 |
class BioethicsChatbot:
|
| 34 |
def __init__(self, data_dir: str="data/sample_papers"):
|
| 35 |
self.processor = DocumentProcessor()
|