Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,18 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
model_name = "nlpai-lab/kobert-base-v1"
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
-
model =
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
"""
|
| 18 |
-
|
| 19 |
-
def answer(question):
|
| 20 |
-
try:
|
| 21 |
-
result = qa_pipeline(question=question, context=context)
|
| 22 |
-
return result["answer"]
|
| 23 |
-
except:
|
| 24 |
-
return "μ£μ‘ν©λλ€. κ·Έ μ§λ¬Έμ λν λ΅μ μ°Ύμ§ λͺ»νμ΄μ."
|
| 25 |
-
|
| 26 |
-
gr.Interface(
|
| 27 |
-
fn=answer,
|
| 28 |
-
inputs="text",
|
| 29 |
-
outputs="text",
|
| 30 |
-
title="μ
μ λμ°λ―Έ AI (KoBERT)",
|
| 31 |
-
description="νκ΅μ΄ KoBERT λͺ¨λΈμ μ¬μ©ν μ
μ μ 보 Q&A AIμ
λλ€."
|
| 32 |
-
).launch()
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM, pipeline
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
+
model_name = "kykim/bert-kor-base"
|
|
|
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 6 |
+
model = AutoModelForMaskedLM.from_pretrained(model_name)
|
| 7 |
+
fill_mask = pipeline("fill-mask", model=model, tokenizer=tokenizer)
|
| 8 |
|
| 9 |
+
def answer(text):
|
| 10 |
+
masked = text.replace("___", fill_mask.tokenizer.mask_token)
|
| 11 |
+
result = fill_mask(masked)
|
| 12 |
+
return result[0]["sequence"]
|
| 13 |
|
| 14 |
+
gr.Interface(fn=answer,
|
| 15 |
+
inputs="text",
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="μ
μ AI (BERT κ²½λ λ²μ )",
|
| 18 |
+
description="λ¬Έμ₯ μμ± κΈ°λ° μ
μ μ 보 μ±λ΄").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|