Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
-
# Hugging Face
|
| 6 |
-
model_name = "
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
# ์ฃผ์ด์ง ์
๋ ฅ์ ๊ธฐ๋ฐํ์ฌ ํด์ฆ๋ฅผ ์์ฑํ๋ ํจ์
|
| 12 |
-
input_text = f"ํด์ฆ: {prompt} ๋๋ต:"
|
| 13 |
-
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
| 14 |
-
|
| 15 |
-
# ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ํด์ฆ ์์ฑ
|
| 16 |
-
output = model.generate(input_ids)
|
| 17 |
-
question = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 18 |
-
|
| 19 |
-
return question
|
| 20 |
-
|
| 21 |
-
# Gradio๋ฅผ ์ฌ์ฉํ์ฌ ์น ์ธํฐํ์ด์ค๋ฅผ ๋ง๋ญ๋๋ค.
|
| 22 |
iface = gr.Interface(
|
| 23 |
-
fn=
|
| 24 |
-
inputs="
|
| 25 |
outputs="text",
|
| 26 |
live=True,
|
| 27 |
-
|
| 28 |
)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering
|
|
|
|
| 3 |
|
| 4 |
+
# Hugging Face ๋ชจ๋ธ ๋ก๋
|
| 5 |
+
model_name = "distilbert-base-cased-distilled-squad"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
| 8 |
+
qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
|
| 9 |
|
| 10 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
iface = gr.Interface(
|
| 12 |
+
fn=lambda question: qa_pipeline(question=question, context=context)["answer"],
|
| 13 |
+
inputs=gr.Textbox(prompt="Enter a question"),
|
| 14 |
outputs="text",
|
| 15 |
live=True,
|
| 16 |
+
capture_session=True,
|
| 17 |
)
|
| 18 |
|
| 19 |
+
# ์ธํฐํ์ด์ค ์คํ
|
| 20 |
iface.launch()
|