Spaces:
Runtime error
Runtime error
Mel Nguyen (she/her)
commited on
Commit
•
20cb92b
1
Parent(s):
c189ee5
update app.py
Browse files
app.py
CHANGED
@@ -10,15 +10,15 @@ def load_model(model_name):
|
|
10 |
return model
|
11 |
|
12 |
model = load_model("VietAI/gpt-neo-1.3B-vietnamese-news")
|
13 |
-
def infer(input_ids, max_length
|
14 |
|
15 |
output_sequences = model.generate(
|
16 |
input_ids=input_ids,
|
17 |
max_length=max_length,
|
18 |
do_sample=True,
|
19 |
-
temperature=
|
20 |
-
top_k=
|
21 |
-
top_p=top_p,
|
22 |
#num_return_sequences=1
|
23 |
)
|
24 |
|
@@ -32,19 +32,23 @@ st.write("It might be a bit slow after you change the generated text length. Be
|
|
32 |
|
33 |
sent = st.text_area("Text", default_value, height = 275)
|
34 |
max_length = st.sidebar.slider("Max Length", min_value = 10, max_value=500)
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
38 |
|
39 |
if st.button("Generate Text"):
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
|
50 |
st.write("For feedback/requests, write to [email protected].")
|
|
|
10 |
return model
|
11 |
|
12 |
model = load_model("VietAI/gpt-neo-1.3B-vietnamese-news")
|
13 |
+
def infer(input_ids, max_length):
|
14 |
|
15 |
output_sequences = model.generate(
|
16 |
input_ids=input_ids,
|
17 |
max_length=max_length,
|
18 |
do_sample=True,
|
19 |
+
temperature=0.9,
|
20 |
+
top_k=20,
|
21 |
+
#top_p=top_p,
|
22 |
#num_return_sequences=1
|
23 |
)
|
24 |
|
|
|
32 |
|
33 |
sent = st.text_area("Text", default_value, height = 275)
|
34 |
max_length = st.sidebar.slider("Max Length", min_value = 10, max_value=500)
|
35 |
+
|
36 |
+
# We don't really need these params. It's a lot slower.
|
37 |
+
# temperature = st.sidebar.slider("Temperature", value = 1.0, min_value = 0.0, max_value=1.0, step=0.05)
|
38 |
+
# top_k = st.sidebar.slider("Top-k", min_value = 0, max_value=5, value = 0)
|
39 |
+
# top_p = st.sidebar.slider("Top-p", min_value = 0.0, max_value=1.0, step = 0.05, value = 0.9)
|
40 |
|
41 |
if st.button("Generate Text"):
|
42 |
+
with st.spinner("Working Hard..."):
|
43 |
+
encoded_prompt = tokenizer.encode(sent, add_special_tokens=False, return_tensors="pt")
|
44 |
+
if encoded_prompt.size()[-1] == 0:
|
45 |
+
input_ids = None
|
46 |
+
else:
|
47 |
+
input_ids = encoded_prompt
|
48 |
+
|
49 |
+
gen_tokens = infer(encoded_prompt, max_length)
|
50 |
+
gen_text = tokenizer.batch_decode(gen_tokens)[0]
|
51 |
+
st.write(gen_text)
|
52 |
+
st.success("Done!")
|
53 |
|
54 |
st.write("For feedback/requests, write to [email protected].")
|