snoop2head commited on
Commit
5ac8ef8
โ€ข
1 Parent(s): 47f452f

initial commit

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ import numpy as np
3
+ import streamlit as st
4
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
+
6
+
7
+ st.set_page_config(
8
+ page_title="", layout="wide", initial_sidebar_state="expanded"
9
+ )
10
+
11
+ @st.cache
12
+ def load_model(model_name):
13
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
14
+ return model
15
+
16
+ tokenizer = AutoTokenizer.from_pretrained("snoop2head/KoBrailleT5-small-v1")
17
+ model = load_model("snoop2head/KoBrailleT5-small-v1")
18
+
19
+
20
+ st.title("ํ•œ๊ตญ์–ด ์ ์—ญ๊ณผ ์—ญ์ ์—ญ")
21
+ st.write("Braille Pattern Conversion")
22
+
23
+
24
+ default_value = '์œ„์Šคํ‚ค ๋ธŒ๋žœ๋”” ๋ธ”๋ฃจ์ง„ ํ•˜์ดํž'
25
+ src_text = st.text_area(
26
+ "๋ฒˆ์—ญํ•˜๊ณ  ์‹ถ์€ ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜์„ธ์š”:",
27
+ default_value,
28
+ height=300,
29
+ max_chars=100,
30
+ )
31
+ print(src_text)
32
+
33
+
34
+
35
+ if src_text == "":
36
+ st.warning("Please **enter text** for translation")
37
+ else:
38
+ # translate into english sentence
39
+
40
+ translation_result = model.generate(
41
+ **tokenizer(
42
+ src_text,
43
+ return_tensors="pt",
44
+ padding="max_length",
45
+ truncation=True,
46
+ max_length=64,
47
+ ),
48
+ max_length=64,
49
+ num_beams=5,
50
+ repetition_penalty=1.3,
51
+ no_repeat_ngram_size=3,
52
+ num_return_sequences=1,
53
+ )
54
+ translation_result = tokenizer.decode(
55
+ translation_result[0],
56
+ clean_up_tokenization_spaces=True,
57
+ skip_special_tokens=True,
58
+ )
59
+
60
+ print(f"{src_text} -> {translation_result}")
61
+
62
+ st.write(translation_result)
63
+ print(translation_result)