Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,27 @@ model_id = "knkarthick/TOPIC-DIALOGSUM"
|
|
| 4 |
|
| 5 |
generator = pipeline(task="text2text-generation", model=model_id)
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def launch(input):
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
iface = gr.Interface(launch, inputs="text", outputs="text")
|
| 11 |
iface.launch()
|
|
|
|
| 4 |
|
| 5 |
generator = pipeline(task="text2text-generation", model=model_id)
|
| 6 |
|
| 7 |
+
def split_paragraph(paragraph, max_chunk_size=1024):
|
| 8 |
+
words = paragraph.split()
|
| 9 |
+
chunks = []
|
| 10 |
+
current_chunk = []
|
| 11 |
+
|
| 12 |
+
for word in words:
|
| 13 |
+
if len(current_chunk) + len(word) + 1 <= max_chunk_size:
|
| 14 |
+
current_chunk.append(word)
|
| 15 |
+
else:
|
| 16 |
+
chunks.append(' '.join(current_chunk))
|
| 17 |
+
current_chunk = [word]
|
| 18 |
+
|
| 19 |
+
if current_chunk:
|
| 20 |
+
chunks.append(' '.join(current_chunk))
|
| 21 |
+
|
| 22 |
+
return chunks
|
| 23 |
+
|
| 24 |
def launch(input):
|
| 25 |
+
if len(input) > 1024:
|
| 26 |
+
return " ".join([res.generated_text for res in generator(split_paragraph(input))])
|
| 27 |
+
return generator(input)[0].generated_text
|
| 28 |
|
| 29 |
iface = gr.Interface(launch, inputs="text", outputs="text")
|
| 30 |
iface.launch()
|