dialogsum / app.py
spuun's picture
Update app.py
38a3929
raw
history blame
871 Bytes
import gradio as gr
from transformers import pipeline
model_id = "knkarthick/TOPIC-DIALOGSUM"
generator = pipeline(task="text2text-generation", model=model_id)
def split_paragraph(paragraph, max_chunk_size=1024):
words = paragraph.split()
chunks = []
current_chunk = []
for word in words:
if len(current_chunk) + len(word) + 1 <= max_chunk_size:
current_chunk.append(word)
else:
chunks.append(' '.join(current_chunk))
current_chunk = [word]
if current_chunk:
chunks.append(' '.join(current_chunk))
return chunks
def launch(input):
if len(input) > 1024:
return " ".join([res["generated_text"] for res in generator(split_paragraph(input, 1024))])
return generator(input)[0]["generated_text"]
iface = gr.Interface(launch, inputs="text", outputs="text")
iface.launch()