Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
| 17 |
#os.system('conda install -c conda-forge poppler')
|
| 18 |
import streamlit as st
|
| 19 |
st.set_page_config(page_title="Summarization Tool", layout="wide", initial_sidebar_state="expanded")
|
| 20 |
-
st.title("
|
| 21 |
import torch
|
| 22 |
import docx2txt
|
| 23 |
from PIL import Image
|
|
@@ -170,41 +170,6 @@ def main():
|
|
| 170 |
bansum(text)
|
| 171 |
if c9.button("English"):
|
| 172 |
engsum(text)
|
| 173 |
-
|
| 174 |
-
with st.container():
|
| 175 |
-
from streamlit_chat import message as st_message
|
| 176 |
-
from transformers import BlenderbotTokenizer
|
| 177 |
-
from transformers import BlenderbotForConditionalGeneration
|
| 178 |
-
st.title("Chatbot!!!")
|
| 179 |
-
|
| 180 |
-
@st.experimental_singleton
|
| 181 |
-
def get_models():
|
| 182 |
-
# it may be necessary for other frameworks to cache the model
|
| 183 |
-
# seems pytorch keeps an internal state of the conversation
|
| 184 |
-
model_name = "facebook/blenderbot-400M-distill"
|
| 185 |
-
tokenizer = BlenderbotTokenizer.from_pretrained(model_name)
|
| 186 |
-
model = BlenderbotForConditionalGeneration.from_pretrained(model_name)
|
| 187 |
-
return tokenizer, model
|
| 188 |
-
if "history" not in st.session_state:
|
| 189 |
-
st.session_state.history = []
|
| 190 |
-
# st.title("Hello bot: ")
|
| 191 |
-
def generate_answer():
|
| 192 |
-
tokenizer, model = get_models()
|
| 193 |
-
user_message = st.session_state.input_text
|
| 194 |
-
inputs = tokenizer(st.session_state.input_text, return_tensors="pt")
|
| 195 |
-
result = model.generate(**inputs)
|
| 196 |
-
message_bot = tokenizer.decode(
|
| 197 |
-
result[0], skip_special_tokens=True
|
| 198 |
-
) # .replace("<s>", "").replace("</s>", "")
|
| 199 |
-
st.session_state.history.append({"message": user_message, "is_user": True})
|
| 200 |
-
st.session_state.history.append({"message": message_bot, "is_user": False})
|
| 201 |
-
from copyreg import clear_extension_cache
|
| 202 |
-
if st.session_state.history!=[]:
|
| 203 |
-
for chat in st.session_state.history:
|
| 204 |
-
st_message(**chat)
|
| 205 |
-
st.text_input("Talk to the bot", key="input_text", on_change=generate_answer)
|
| 206 |
-
if st.button("Refresh/New Chat"):
|
| 207 |
-
st.session_state.history = []
|
| 208 |
|
| 209 |
if __name__ == "__main__":
|
| 210 |
main()
|
|
|
|
| 17 |
#os.system('conda install -c conda-forge poppler')
|
| 18 |
import streamlit as st
|
| 19 |
st.set_page_config(page_title="Summarization Tool", layout="wide", initial_sidebar_state="expanded")
|
| 20 |
+
st.title("Bangla/English Text Summarizer: Upload Images/Pdf or input texts to summarize!")
|
| 21 |
import torch
|
| 22 |
import docx2txt
|
| 23 |
from PIL import Image
|
|
|
|
| 170 |
bansum(text)
|
| 171 |
if c9.button("English"):
|
| 172 |
engsum(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
if __name__ == "__main__":
|
| 175 |
main()
|