Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import AutoModelWithLMHead, AutoTokenizer | |
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap") | |
model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap") | |
def get_question(context, answer, max_length=64): | |
input_text = "answer: %s context: %s </s>" % (answer, context) | |
features = tokenizer([input_text], return_tensors='pt') | |
output = model.generate(input_ids=features['input_ids'], | |
attention_mask=features['attention_mask'], | |
max_length=max_length) | |
return tokenizer.decode(output[0])[16:-4] | |
examples = [["Uzbekistan is a Central Asian nation and former Soviet republic. It's known for its mosques, mausoleums and other sites linked to the Silk Road, the ancient trade route between China and the Mediterranean. Samarkand, a major city on the route, contains a landmark of Islamic architecture.", "Silk Road"]] | |
css = """ | |
.output-markdown{display:none !important} | |
.gr-button-primary { | |
z-index: 14; | |
height: 43px; | |
width: 130px; | |
left: 0px; | |
top: 0px; | |
padding: 0px; | |
cursor: pointer !important; | |
background: none rgb(17, 20, 45) !important; | |
border: none !important; | |
text-align: center !important; | |
font-family: Poppins !important; | |
font-size: 14px !important; | |
font-weight: 500 !important; | |
color: rgb(255, 255, 255) !important; | |
line-height: 1 !important; | |
border-radius: 12px !important; | |
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important; | |
box-shadow: none !important; | |
} | |
.gr-button-primary:hover{ | |
z-index: 14; | |
height: 43px; | |
width: 130px; | |
left: 0px; | |
top: 0px; | |
padding: 0px; | |
cursor: pointer !important; | |
background: none rgb(37, 56, 133) !important; | |
border: none !important; | |
text-align: center !important; | |
font-family: Poppins !important; | |
font-size: 14px !important; | |
font-weight: 500 !important; | |
color: rgb(255, 255, 255) !important; | |
line-height: 1 !important; | |
border-radius: 12px !important; | |
transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important; | |
box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important; | |
} | |
.hover\:bg-orange-50:hover { | |
--tw-bg-opacity: 1 !important; | |
background-color: rgb(229,225,255) !important; | |
} | |
""" | |
demo = 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", examples=examples, css=css) | |
demo.launch() |