Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
from arabert.preprocess import ArabertPreprocessor | |
arabert_prep = ArabertPreprocessor(model_name="araelectra-base-discriminator") | |
qa_pipeline = pipeline( | |
"question-answering", | |
model="ZeyadAhmed/AraElectra-Arabic-SQuADv2-QA", | |
tokenizer="ZeyadAhmed/AraElectra-Arabic-SQuADv2-QA" | |
) | |
def answer_question(context, question): | |
context_processed = arabert_prep.preprocess(context) | |
question_processed = arabert_prep.preprocess(question) | |
result = qa_pipeline({ | |
"context": context_processed, | |
"question": question_processed | |
}) | |
return result["answer"] | |
demo = gr.Interface( | |
fn=answer_question, | |
inputs=[gr.Textbox(label="النص الكامل (Context)"), gr.Textbox(label="السؤال (Question)")], | |
outputs="text", | |
title="سؤال وجواب بالعربية باستخدام AraElectra" | |
) | |
demo.launch(share=True, server_name="0.0.0.0", server_port=7860 ) | |