Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,32 @@
|
|
1 |
-
import
|
2 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
if __name__ == "__main__":
|
24 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
3 |
|
4 |
+
def generate_diary(keywords):
|
5 |
+
# ๋ชจ๋ธ ๋ฐ ํ ํฌ๋์ด์ ๋ก๋
|
6 |
+
model = GPT2LMHeadModel.from_pretrained("gpt2")
|
7 |
+
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
8 |
+
|
9 |
+
# ํค์๋ ๊ธฐ๋ฐ fine-tuning
|
10 |
+
input_ids = tokenizer.encode(" ".join(keywords), return_tensors="pt")
|
11 |
+
output = model.generate(input_ids, max_length=500, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95, num_beams=5)
|
12 |
+
|
13 |
+
# ์์ฑ๋ ์ผ๊ธฐ ํ
์คํธ ๋ฐํ
|
14 |
+
diary = tokenizer.decode(output[0], skip_special_tokens=True)
|
15 |
+
return diary
|
16 |
|
17 |
+
def app():
|
18 |
+
with gr.Blocks() as demo:
|
19 |
+
gr.Markdown("# ์๋ ์ผ๊ธฐ ์์ฑ๊ธฐ")
|
|
|
20 |
|
21 |
+
with gr.Row():
|
22 |
+
keywords = gr.Textbox(label="5๊ฐ์ ํค์๋๋ฅผ ์
๋ ฅํ์ธ์ (์ผํ๋ก ๊ตฌ๋ถ)")
|
23 |
+
generate_btn = gr.Button("์ผ๊ธฐ ์ฐ๊ธฐ")
|
24 |
|
25 |
+
diary = gr.Textbox(label="์์ฑ๋ ์ผ๊ธฐ")
|
26 |
+
|
27 |
+
generate_btn.click(generate_diary, inputs=keywords, outputs=diary)
|
28 |
+
|
29 |
+
demo.launch()
|
30 |
|
31 |
if __name__ == "__main__":
|
32 |
+
app()
|