Galuh Sahid commited on
Commit
d356c04
1 Parent(s): 0f2a50b

Add language prediction, translation

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -50,7 +50,7 @@ st.set_page_config(page_title="Indonesian GPT-2 Demo")
50
 
51
  st.title("Indonesian GPT-2")
52
 
53
- # ft_model = fasttext.load_model('lid.176.ftz')
54
 
55
  # Sidebar
56
  st.sidebar.image(LOGO)
@@ -119,6 +119,12 @@ text = st.text_area("Enter text", session_state.prompt_box)
119
 
120
  if st.button("Run"):
121
  with st.spinner(text="Getting results..."):
 
 
 
 
 
 
122
 
123
  st.subheader("Result")
124
  model = load_gpt(model_name)
@@ -138,3 +144,19 @@ if st.button("Run"):
138
 
139
  st.text("Translation")
140
  translation = translate(text, "en", "id")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  st.title("Indonesian GPT-2")
52
 
53
+ ft_model = fasttext.load_model('lid.176.ftz')
54
 
55
  # Sidebar
56
  st.sidebar.image(LOGO)
 
119
 
120
  if st.button("Run"):
121
  with st.spinner(text="Getting results..."):
122
+ lang_predictions, lang_probability = ft_model.predict(text.replace("\n", " "), k=3)
123
+ if "__label__id" in lang_predictions:
124
+ lang = "id"
125
+ else:
126
+ lang = lang_predictions[0].replace("__label__", "")
127
+ text = translate(text, "id", lang)
128
 
129
  st.subheader("Result")
130
  model = load_gpt(model_name)
 
144
 
145
  st.text("Translation")
146
  translation = translate(text, "en", "id")
147
+
148
+ if lang == "id":
149
+ st.write(translation.replace("\n", " \n"))
150
+
151
+ else:
152
+ st.write(translate(result, lang, "id").replace("\n", " \n"))
153
+
154
+ image_cat = "https://media.giphy.com/media/vFKqnCdLPNOKc/giphy.gif"
155
+ image = get_image(translation.replace("\"", "'"))
156
+
157
+ if image is not "":
158
+ st.image(image, width=400)
159
+
160
+ else:
161
+ # display cat image if no image found
162
+ st.image(image_cat, width=400)