Spaces:
Runtime error
Runtime error
Galuh Sahid
commited on
fix reload
Browse files
app.py
CHANGED
@@ -106,12 +106,17 @@ elif model_name in ["GPT-2 Small finetuned on Indonesian academic journals"]:
|
|
106 |
session_state = SessionState.get(prompt=None, prompt_box=None, text=None)
|
107 |
|
108 |
ALL_PROMPTS = list(PROMPT_LIST[prompt_group_name].keys())+["Custom"]
|
109 |
-
|
|
|
|
|
|
|
|
|
110 |
|
111 |
if session_state.prompt == "Custom":
|
112 |
session_state.prompt_box = "Enter your text here"
|
113 |
else:
|
114 |
-
session_state.prompt_box
|
|
|
115 |
|
116 |
session_state.text = st.text_area("Enter text", session_state.prompt_box)
|
117 |
|
@@ -120,6 +125,7 @@ if st.button("Run"):
|
|
120 |
lang_predictions, lang_probability = ft_model.predict(session_state.text.replace("\n", " "), k=3)
|
121 |
if "__label__id" in lang_predictions:
|
122 |
lang = "id"
|
|
|
123 |
else:
|
124 |
lang = lang_predictions[0].replace("__label__", "")
|
125 |
text = translate(session_state.text, "id", lang)
|
@@ -158,3 +164,8 @@ if st.button("Run"):
|
|
158 |
else:
|
159 |
# display cat image if no image found
|
160 |
st.image(image_cat, width=400)
|
|
|
|
|
|
|
|
|
|
|
|
106 |
session_state = SessionState.get(prompt=None, prompt_box=None, text=None)
|
107 |
|
108 |
ALL_PROMPTS = list(PROMPT_LIST[prompt_group_name].keys())+["Custom"]
|
109 |
+
prompt = st.selectbox('Prompt', ALL_PROMPTS, index=len(ALL_PROMPTS)-1)
|
110 |
+
|
111 |
+
if session_state.prompt is not None and (prompt != session_state.prompt):
|
112 |
+
session_state.prompt_box = None
|
113 |
+
session_state.text = None
|
114 |
|
115 |
if session_state.prompt == "Custom":
|
116 |
session_state.prompt_box = "Enter your text here"
|
117 |
else:
|
118 |
+
if session_state.prompt_box is None:
|
119 |
+
session_state.prompt_box = random.choice(PROMPT_LIST[prompt_group_name][session_state.prompt])
|
120 |
|
121 |
session_state.text = st.text_area("Enter text", session_state.prompt_box)
|
122 |
|
|
|
125 |
lang_predictions, lang_probability = ft_model.predict(session_state.text.replace("\n", " "), k=3)
|
126 |
if "__label__id" in lang_predictions:
|
127 |
lang = "id"
|
128 |
+
text = session_state.text
|
129 |
else:
|
130 |
lang = lang_predictions[0].replace("__label__", "")
|
131 |
text = translate(session_state.text, "id", lang)
|
|
|
164 |
else:
|
165 |
# display cat image if no image found
|
166 |
st.image(image_cat, width=400)
|
167 |
+
|
168 |
+
# Reset state
|
169 |
+
session_state.prompt = None
|
170 |
+
session_state.prompt_box = None
|
171 |
+
session_state.text = None
|