Spaces:
Runtime error
Runtime error
File size: 2,970 Bytes
6d92158 59c5207 3060053 59c5207 4e58ddc 942c42a 5074ad0 6732406 0952100 6732406 3060053 59c5207 4e58ddc 6732406 5074ad0 4e58ddc 6d92158 5074ad0 59c5207 5074ad0 f34d241 59c5207 038f7f8 59c5207 |
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 32 33 34 35 36 37 38 |
import gradio as gr
from inductor import BartInductor
inductor = BartInductor()
def bart(text):
results = inductor.generate(text, return_scores=True)
#results=[('<mask> is the capital and largest city of <mask>.', 0.0075895977795922415), ('<mask> is the largest city in <mask>.', 0.005302619071099926), ('<mask> is the most populous state in <mask>.', 0.0036559513972044544), ('<mask> is the capital of <mask>.', 0.0028800265140167813), ('<mask> is a state in <mask>.', 0.002295685033583364), ('<mask> is a capital of <mask>.', 0.001348920570936385), ('<mask> has one of the highest rates of poverty in <mask>.', 0.0012284877234430835), ('<mask> is a major commercial and financial centre of <mask>.', 0.001225910195650215), ('<mask> was then a part of <mask>.', 0.0007620440367924856), ('<mask>, the capital of the country, is the largest city in <mask>.', 0.0006940517028590776)]
results = [(result[0], float(result[1]) * 100) for result in results]
results_dict = {result[0]: float(result[1]) for result in results}
return results_dict
def bart2(text):
#results = inductor.generate(text)
results=[('<mask> is the capital and largest city of <mask>.', 0.0075895977795922415), ('<mask> is the largest city in <mask>.', 0.005302619071099926), ('<mask> is the most populous state in <mask>.', 0.0036559513972044544), ('<mask> is the capital of <mask>.', 0.0028800265140167813), ('<mask> is a state in <mask>.', 0.002295685033583364), ('<mask> is a capital of <mask>.', 0.001348920570936385), ('<mask> has one of the highest rates of poverty in <mask>.', 0.0012284877234430835), ('<mask> is a major commercial and financial centre of <mask>.', 0.001225910195650215), ('<mask> was then a part of <mask>.', 0.0007620440367924856), ('<mask>, the capital of the country, is the largest city in <mask>.', 0.0006940517028590776)]
results = [(result[0], float(result[1]) * 100) for result in results]
results_dict = {result[0]: float(result[1]) for result in results}
return results_dict
bivar = gr.Interface(fn=bart,
inputs=gr.inputs.Textbox(default='<mask> is the capital of <mask>.'),
outputs=gr.Label(),
title="BART Inductor εει",
examples=[['<mask> is the capital of <mask>.'],['<mask> is founder of <mask>.']],
description="Enter a text prompt to generate text using BART.")
trivar = gr.Interface(fn=bart2,
inputs=gr.inputs.Textbox(default='<mask> is the parent of <mask>, who is the sibling of <mask>.'),
outputs=gr.Label(),
title="BART Inductor δΈει",
examples=[['<mask> is the parent of <mask>, who is the sibling of <mask>.']],
description="Still working on it!!!!!!!!!!!!!!!!!!!!")
demo = gr.TabbedInterface([bivar, trivar], ["εει", "δΈει"])
if __name__ == "__main__":
demo.launch()
|