|
from langchain.text_splitter import CharacterTextSplitter |
|
from langchain.docstore.document import Document |
|
from langchain.chains.summarize import load_summarize_chain |
|
from langchain import OpenAI, LLMChain, HuggingFaceHub |
|
import textwrap |
|
|
|
|
|
def summarize(doc): |
|
text_splitter = CharacterTextSplitter(chunk_size=500, chunk_overlap=0, |
|
separator="\n") |
|
chunks = text_splitter.split_text(doc) |
|
doc_store = [Document(page_content=text) for text in chunks] |
|
llm_model = OpenAI(model_name="text-davinci-003", temperature=0) |
|
|
|
summarization_chain2 = load_summarize_chain(llm=llm_model, |
|
chain_type='map_reduce', |
|
verbose=True |
|
) |
|
output_summary = summarization_chain2.run(doc_store) |
|
wrapped_text = textwrap.fill(output_summary, width=100) |
|
|
|
return wrapped_text |
|
|
|
if __name__ == "__main__": |
|
|
|
import gradio as gr |
|
|
|
outputs = gr.outputs.Textbox() |
|
|
|
app = gr.Interface(fn=summarize, inputs='text', outputs=outputs,description="This is a text summarization model").launch() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|