Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
model = "hosseinhimself/tara-roberta-base-fa-qa"
|
5 |
+
|
6 |
+
# Load the tokenizer and model
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
8 |
+
model = AutoModelForQuestionAnswering.from_pretrained(model)
|
9 |
+
|
10 |
+
# Create a QA pipeline
|
11 |
+
qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
|
12 |
+
|
13 |
+
|
14 |
+
def answer_question(context, question):
|
15 |
+
response = qa_pipeline(question=question, context=context)
|
16 |
+
return response['answer']
|
17 |
+
|
18 |
+
# Define the Gradio interface
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=answer_question,
|
21 |
+
inputs=[
|
22 |
+
gr.inputs.Textbox(lines=10, placeholder="Enter context here..."),
|
23 |
+
gr.inputs.Textbox(lines=1, placeholder="Enter question here...")
|
24 |
+
],
|
25 |
+
outputs="text",
|
26 |
+
title="Tara Question Answering Model",
|
27 |
+
description="This model answers questions based on the provided context."
|
28 |
+
)
|
29 |
+
|
30 |
+
# Launch the interface
|
31 |
+
interface.launch()
|