import gradio as gr from transformers import pipeline import json data = open('source_dict.txt', 'r') source_dict = json.loads(data.read()) def getScore(summary, chapter): text = summary + '' + source_dict[chapter] pipe1 = pipeline('text-classification', model='tiedaar/summary-longformer-wording', function_to_apply="none") pipe2 = pipeline('text-classification', model='tiedaar/summary-longformer-content', function_to_apply="none") return pipe1(text)[0]['score'], pipe2(text)[0]['score'] demo = gr.Interface( fn=getScore, inputs=[gr.Textbox(lines=2, placeholder="Summary..."), gr.Dropdown(label = "Chapter", choices = list(source_dict.keys())),], outputs=[gr.Number(label = "Wording Score"), gr.Number(label="Content Score")], title="Automatic Summary Scorer", description="Automatic Summary Scorer for OpenStax Macroeconomics Textbook", article="This is an app which provides two scores for summaries of chapters in the OpenStax textbook on Macroeconomics. The source text can be found at https://openstax.org/books/principles-macroeconomics-ap-courses-2e/pages/1-key-concepts-and-summary" ) demo.launch()