Spaces:
Runtime error
Runtime error
add new branch for multiple models
Browse files- app/app.py +21 -5
- app/prompts.py +18 -16
app/app.py
CHANGED
@@ -10,17 +10,29 @@ import psutil
|
|
10 |
|
11 |
# st.set_page_config(page_title="Indonesian Story Generator")
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
@st.cache(suppress_st_warning=True, allow_output_mutation=True)
|
18 |
-
def get_generator():
|
19 |
st.write(f"Loading the GPT2 model {model_name}, please wait...")
|
20 |
text_generator = pipeline('text-generation', model=model_name)
|
21 |
return text_generator
|
22 |
|
23 |
-
|
24 |
@st.cache(suppress_st_warning=True, hash_funcs={tokenizers.Tokenizer: id})
|
25 |
def process(text: str, max_length: int = 100, do_sample: bool = True, top_k: int = 50, top_p: float = 0.95,
|
26 |
temperature: float = 1.0, max_time: float = 10.0, seed=42):
|
@@ -39,9 +51,13 @@ st.markdown(
|
|
39 |
This application is a demo for Indonesian Story Generator using GPT2.
|
40 |
"""
|
41 |
)
|
|
|
|
|
42 |
session_state = SessionState.get(prompt=None, prompt_box=None, text=None)
|
43 |
-
|
|
|
44 |
prompt = st.selectbox('Prompt', ALL_PROMPTS, index=len(ALL_PROMPTS)-1)
|
|
|
45 |
# Update prompt
|
46 |
if session_state.prompt is None:
|
47 |
session_state.prompt = prompt
|
|
|
10 |
|
11 |
# st.set_page_config(page_title="Indonesian Story Generator")
|
12 |
|
13 |
+
MODELS = {
|
14 |
+
"GPT-2 Small finetuned on Indonesian stories": {
|
15 |
+
"name": "cahya/gpt2-small-indonesian-story"
|
16 |
+
},
|
17 |
+
"GPT-2 Medium finetuned on Indonesian stories": {
|
18 |
+
"name": "cahya/gpt2-medium-indonesian-story"
|
19 |
+
},
|
20 |
+
}
|
21 |
+
|
22 |
+
model = st.selectbox('Model',([
|
23 |
+
'GPT-2 Small finetuned on Indonesian stories',
|
24 |
+
'GPT-2 Medium finetuned on Indonesian stories']))
|
25 |
+
|
26 |
+
if model in ["GPT-2 Small finetuned on Indonesian stories", "GPT-2 Medium finetuned on Indonesian stories"]:
|
27 |
+
prompt_group_name = "Indonesian Stories"
|
28 |
|
29 |
|
30 |
@st.cache(suppress_st_warning=True, allow_output_mutation=True)
|
31 |
+
def get_generator(model_name: str):
|
32 |
st.write(f"Loading the GPT2 model {model_name}, please wait...")
|
33 |
text_generator = pipeline('text-generation', model=model_name)
|
34 |
return text_generator
|
35 |
|
|
|
36 |
@st.cache(suppress_st_warning=True, hash_funcs={tokenizers.Tokenizer: id})
|
37 |
def process(text: str, max_length: int = 100, do_sample: bool = True, top_k: int = 50, top_p: float = 0.95,
|
38 |
temperature: float = 1.0, max_time: float = 10.0, seed=42):
|
|
|
51 |
This application is a demo for Indonesian Story Generator using GPT2.
|
52 |
"""
|
53 |
)
|
54 |
+
|
55 |
+
|
56 |
session_state = SessionState.get(prompt=None, prompt_box=None, text=None)
|
57 |
+
|
58 |
+
ALL_PROMPTS = list(PROMPT_LIST[prompt_group_name].keys())+["Custom"]
|
59 |
prompt = st.selectbox('Prompt', ALL_PROMPTS, index=len(ALL_PROMPTS)-1)
|
60 |
+
|
61 |
# Update prompt
|
62 |
if session_state.prompt is None:
|
63 |
session_state.prompt = prompt
|
app/prompts.py
CHANGED
@@ -1,18 +1,20 @@
|
|
1 |
PROMPT_LIST = {
|
2 |
-
"
|
3 |
-
"
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
"
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
"
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
}
|
|
|
1 |
PROMPT_LIST = {
|
2 |
+
"Indonesian Stories": {
|
3 |
+
"Adult Romance": [
|
4 |
+
"Ini adalah kisah tentang seorang laki-laki yang berusaha memperjuangkan cintanya",
|
5 |
+
"Alunan musik terdengar memenuhi ruangan kantor, cowok itu duduk di balik meja kerjanya sambil memejamkan mata. Berusaha meresapi nada per nada",
|
6 |
+
"Aku mencari dan terus mencari\nDimana bahagia akan kutemui\nKumencari terus mencari\nHingga ku tak mengerti arti hari-hari",
|
7 |
+
"Gadis itu mengharuskan dirinya tegar, dan kuat dalam menghadapi masalah. Menahan air matanya jatuh setiap kali ingin menangis"
|
8 |
+
],
|
9 |
+
"Horror": [
|
10 |
+
"Ditengah-tengah perbincangan mereka berdua, datanglah sesosok mahluk tinggi hitam dan besar",
|
11 |
+
"Sesosok hantu perempuan seperti kuntilanak yang melayang keluar dan bergerak perlahan dari pintu kamar kecil tadi yang tertutup.",
|
12 |
+
"Sejak pertemuannya dengan leak, yang ternyata tinggal satu atap dengannya, hidupnya terus dihantui oleh berbagai sosok seram."
|
13 |
+
],
|
14 |
+
"Poetry": [
|
15 |
+
"Aku ingin menulis sajak\nyang melesat dalam kejap\nmenembus hati yang pejam\nmemaksa mimpimu terjaga\ndari semu",
|
16 |
+
"Malam ini langitku lengang\ntiada hujan yang membasuh rindu\npun awan yang biasanya temani seruput kopimu",
|
17 |
+
"Di sisimu waktu menjelma\nsetangkai kembang api\ngelora membakar tanpa jeda\nmemercik pijar binar kita."
|
18 |
+
]
|
19 |
+
}
|
20 |
}
|