Spaces:
Runtime error
Runtime error
File size: 1,071 Bytes
4770a86 408f343 e61d618 4770a86 955d0d6 817f881 408f343 e61d618 c6f8e5b 7312d2a f52aa82 2dc9e73 e61d618 1477c65 e61d618 05ace25 7312d2a 408f343 4770a86 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import gradio as gr
from transformers import pipeline
import csv
model_id = "philschmid/bart-large-cnn-samsum"
summarizer = pipeline("summarization", model=model_id)
def summarize(text):
text = str(text)
if text == "showdata":
lines = "(lines)"
with open('input.csv',"r") as f:
lines = f.readlines()
return str(lines)
generated_summary_short = summarizer(text, max_length=40, min_length=10)[0]['summary_text']
generated_summary = summarizer(text, max_length=80, min_length=20)[0]['summary_text']
generated_summary_long = summarizer(text, max_length=200, min_length=40)[0]['summary_text']
fields = [str(text), str(generated_summary)]
with open('input.csv','a', newline='') as f:
writer = csv.writer(f)
writer.writerow(fields)
return "Summary: " + str(generated_summary) + "\n\n" + "shorter: " + str(generated_summary_short)+ "\n\n" + "Longer: " + str(generated_summary_long)
iface = gr.Interface(fn=summarize, inputs="text", outputs="text")
iface.launch() |