import gradio as gr from transformers import pipeline # Load the model using Hugging Face's pipeline model_name = "quocviethere/xlmroberta-finetuned-squadv2" qa_pipeline = pipeline('question-answering', model=model_name) # Define a function that the interface will use def answer_question(context, question): return qa_pipeline(context=context, question=question)['answer'] # Define a single example examples = [ ["Tính đến tháng 6/2023, Vườn ươm Viện Đổi mới sáng tạo đã ươm tạo gần 100 dự án khởi nghiệp, trong đó có 19 dự án thành lập công ty, hơn 7600 người tham dự các hoạt động và tổng giá trị đầu tư mạo hiểm đạt 350.000 USD.", "Tổng giá trị đầu tư mạo hiểm của Vườn ươm Viện Đổi mới sáng tạo là bao nhiêu?"] ] # Create the Gradio interface iface = gr.Interface(fn=answer_question, inputs=[ gr.Textbox(lines=7, placeholder="Enter the context here...", label="Context"), gr.Textbox(placeholder="Enter your question here...", label="Question") ], outputs=gr.Textbox(label="Answer"), title='UEH-QA', description='Creating safe AGI that benefits all of humanity.', examples=examples) # Launch the interface iface.launch()