Spaces:
Sleeping
Sleeping
IProject-10
commited on
Commit
•
a194712
1
Parent(s):
b54e082
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,30 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
3 |
-
|
4 |
-
model_name = "IProject-10/roberta-base-finetuned-squad2"
|
5 |
-
nlp = pipeline("question-answering", model=model_name, tokenizer=model_name)
|
6 |
-
|
7 |
-
def predict(context, question):
|
8 |
-
res = nlp({"question": question, "context": context})
|
9 |
-
return res["answer"]
|
10 |
-
|
11 |
-
md = """
|
12 |
-
|
13 |
-
|
14 |
-
""
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
],
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
description=md,
|
32 |
-
).launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
3 |
+
|
4 |
+
model_name = "IProject-10/roberta-base-finetuned-squad2"
|
5 |
+
nlp = pipeline("question-answering", model=model_name, tokenizer=model_name)
|
6 |
+
|
7 |
+
def predict(context, question):
|
8 |
+
res = nlp({"question": question, "context": context})
|
9 |
+
return res["answer"]
|
10 |
+
|
11 |
+
md = """
|
12 |
+
"""
|
13 |
+
|
14 |
+
context = "The Amazon rainforest, also known in English as Amazonia or the Amazon Jungle, is a moist broadleaf forest that covers most of the Amazon basin of South America..."
|
15 |
+
question = "Which continent is the Amazon rainforest in?"
|
16 |
+
|
17 |
+
apple_context = "An apple is an edible fruit produced by an apple tree (Malus domestica)..."
|
18 |
+
apple_question = "How many years have apples been grown for?"
|
19 |
+
|
20 |
+
gr.Interface(
|
21 |
+
predict,
|
22 |
+
inputs=[
|
23 |
+
gr.Textbox(lines=7, value=context, label="Context Paragraph"),
|
24 |
+
gr.Textbox(lines=2, value=question, label="Question"),
|
25 |
+
],
|
26 |
+
outputs=gr.Textbox(label="Answer"),
|
27 |
+
examples=[[apple_context, apple_question]],
|
28 |
+
title="Question Answering System",
|
29 |
+
description=md,
|
30 |
+
).launch()
|
|
|
|