raynardj
commited on
Commit
•
735386f
1
Parent(s):
c70e0dc
🍶 baseline
Browse files
README.md
CHANGED
@@ -1,37 +1,13 @@
|
|
1 |
---
|
2 |
title: Modern Chinese To Ancient Translate Wenyanwen
|
3 |
-
emoji:
|
4 |
colorFrom: gray
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
app_file: app.py
|
8 |
-
pinned:
|
9 |
---
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
Display title for the Space
|
15 |
-
|
16 |
-
`emoji`: _string_
|
17 |
-
Space emoji (emoji-only character allowed)
|
18 |
-
|
19 |
-
`colorFrom`: _string_
|
20 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
21 |
-
|
22 |
-
`colorTo`: _string_
|
23 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
24 |
-
|
25 |
-
`sdk`: _string_
|
26 |
-
Can be either `gradio` or `streamlit`
|
27 |
-
|
28 |
-
`sdk_version` : _string_
|
29 |
-
Only applicable for `streamlit` SDK.
|
30 |
-
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
31 |
-
|
32 |
-
`app_file`: _string_
|
33 |
-
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
34 |
-
Path is relative to the root of the repository.
|
35 |
-
|
36 |
-
`pinned`: _boolean_
|
37 |
-
Whether the Space stays on top of your list.
|
|
|
1 |
---
|
2 |
title: Modern Chinese To Ancient Translate Wenyanwen
|
3 |
+
emoji: 🍶
|
4 |
colorFrom: gray
|
5 |
+
colorTo: cyan
|
6 |
sdk: streamlit
|
7 |
app_file: app.py
|
8 |
+
pinned: true
|
9 |
---
|
10 |
|
11 |
+
# Modern Chinese To Ancient Translate Wenyanwen
|
12 |
+
* Huggingface Model's Model: [wenyanwen-chinese-translate-to-ancient](https://huggingface.co/raynardj/wenyanwen-chinese-translate-to-ancient)
|
13 |
+
* [GitHub](https://github.com/raynardj/yuan)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import (
|
2 |
+
EncoderDecoderModel,
|
3 |
+
AutoTokenizer
|
4 |
+
)
|
5 |
+
import torch
|
6 |
+
|
7 |
+
PRETRAINED = "raynardj/wenyanwen-chinese-translate-to-ancient"
|
8 |
+
|
9 |
+
def inference(text):
|
10 |
+
tk_kwargs = dict(
|
11 |
+
truncation=True,
|
12 |
+
max_length=128,
|
13 |
+
padding="max_length",
|
14 |
+
return_tensors='pt')
|
15 |
+
|
16 |
+
inputs = tokenizer([text,],**tk_kwargs)
|
17 |
+
with torch.no_grad():
|
18 |
+
return tokenizer.batch_decode(
|
19 |
+
model.generate(
|
20 |
+
inputs.input_ids,
|
21 |
+
attention_mask=inputs.attention_mask,
|
22 |
+
num_beams=3,
|
23 |
+
bos_token_id=101,
|
24 |
+
eos_token_id=tokenizer.sep_token_id,
|
25 |
+
pad_token_id=tokenizer.pad_token_id,
|
26 |
+
), skip_special_tokens=True)
|
27 |
+
|
28 |
+
import streamlit as st
|
29 |
+
|
30 |
+
st.title("Wenyanwen Translator")
|
31 |
+
st.markdown("""
|
32 |
+
# Translate from Chinese to Ancient Chinese / 还你古朴清雅壮丽的文言文, 这[github](https://github.com/raynardj/yuan)
|
33 |
+
""")
|
34 |
+
|
35 |
+
@st.cache
|
36 |
+
def load_model():
|
37 |
+
tokenizer = AutoTokenizer.from_pretrained(PRETRAINED)
|
38 |
+
model = EncoderDecoderModel.from_pretrained(PRETRAINED)
|
39 |
+
return tokenizer, model
|
40 |
+
|
41 |
+
tokenizer, model = load_model()
|
42 |
+
|
43 |
+
text = st.text_area("轻轻地我走了,正如我轻轻地来。我挥一挥衣袖,不带走一片云彩。")
|
44 |
+
|
45 |
+
st.write(inference(text)[0])
|