summarymachine / app.py
johnnyfivefingers's picture
Update app.py
1477c65
raw
history blame
1.07 kB
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()