Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pip install transformers gradio
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 4 |
+
|
| 5 |
+
# Hugging Face์ t5-base ๋ชจ๋ธ ๋ฐ ํ ํฌ๋์ด์ ๋ฅผ ๋ถ๋ฌ์ต๋๋ค.
|
| 6 |
+
model_name = "t5-base"
|
| 7 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
| 8 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
def generate_question(prompt):
|
| 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=generate_question,
|
| 24 |
+
inputs="text",
|
| 25 |
+
outputs="text",
|
| 26 |
+
live=True,
|
| 27 |
+
interpretation="default"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# ์น ์๋น์ค๋ฅผ ์์ํฉ๋๋ค.
|
| 31 |
+
iface.launch()
|