import gradio as gr from transformers import pipeline import csv model_id = "pszemraj/long-t5-tglobal-base-16384-book-summary" 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 = 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) return "Summary: " + str(generated_summary) iface = gr.Interface(fn=summarize, inputs="text", outputs="text") iface.launch()