Akbartus/question-gen
0
1import gradio as gr2from transformers import AutoModelWithLMHead, AutoTokenizer3 4tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")5model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")6 7def get_question(context, answer, max_length=64):8 input_text = "answer: %s context: %s </s>" % (answer, context)9 features = tokenizer([input_text], return_tensors='pt')10 11 output = model.generate(input_ids=features['input_ids'], 12 attention_mask=features['attention_mask'],13 max_length=max_length)14 15 return tokenizer.decode(output[0])[16:-4]16 17examples = [["The world's first piece of software was written by a computer scientist named Tom Kilburn in 1948.", "1948"], ["The world's first piece of software was written by a computer scientist named Tom Kilburn in 1948.", "Tom Kilburn"], ["The world's first piece of software was written by a computer scientist named Tom Kilburn in 1948.", "computer scientist"]]18 19css = """20.gr-button-primary {21 z-index: 14;22 height: 43px;23 width: 130px;24 left: 0px;25 top: 0px;26 padding: 0px;27 cursor: pointer !important; 28 background: none rgb(17, 20, 45) !important;29 border: none !important;30 text-align: center !important;31 font-family: Poppins !important;32 font-size: 14px !important;33 font-weight: 500 !important;34 color: rgb(255, 255, 255) !important;35 line-height: 1 !important;36 border-radius: 12px !important;37 transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;38 box-shadow: none !important;39}40.gr-button-primary:hover{41 z-index: 14;42 height: 43px;43 width: 130px;44 left: 0px;45 top: 0px;46 padding: 0px;47 cursor: pointer !important;48 background: none rgb(37, 56, 133) !important;49 border: none !important;50 text-align: center !important;51 font-family: Poppins !important;52 font-size: 14px !important;53 font-weight: 500 !important;54 color: rgb(255, 255, 255) !important;55 line-height: 1 !important;56 border-radius: 12px !important;57 transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;58 box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;59}60.hover\:bg-orange-50:hover {61 --tw-bg-opacity: 1 !important;62 background-color: rgb(229,225,255) !important;63}64"""65demo = gr.Interface(fn=get_question, inputs=[gr.Textbox(lines=3, placeholder="Enter text here", label="Input # 1 - Context"), gr.Textbox(lines=1, label="Input # 2 - Answer")], outputs=gr.Textbox(label="Output - Generated Question"), title="Question Generator | Data Science Dojo", examples=examples, css=css)66demo.launch(show_api=True)