BeardedMonster commited on
Commit
e5e53b2
·
verified ·
1 Parent(s): 89ce0b1

update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -30
app.py CHANGED
@@ -28,29 +28,22 @@ st.sidebar.title("Instructions: How to use")
28
  st.sidebar.write("""
29
  1. **Write Text or Select Sample:**
30
  - Enter text in the text area or use the dropdown to choose a sample.
31
-
32
  2. **Select a Task:**
33
  - Choose a task from the **task dropdown** if using your own text.
34
  - **Important:** This ensures correct model response.
35
-
36
  3. **Avoid Conflicts:**
37
  - Don't select a sample text if using your own text.
38
-
39
  4. **Select Nigerian Language:**
40
  - If prompted, choose the Nigerian language (it represents the input/base language for diacritization/cleaning, target language for translation).
41
-
42
  5. **Generate Output:**
43
  - Click the Generate button.
44
-
45
  6. **Translation Tips:**
46
  - English as the target language gives the best results.
47
  - You can also test inter-language translation i.e yoruba to igbo
48
-
49
  7. **Performance Note:**
50
  - The model's performance varies due to its size and training data. It performs best on text generation and translation.
51
  - For other tasks, try multiple times if model's output is not optimal (This is due to the generator's sampling parameter settings).
52
  - It's best to read/understand/translate the model's output completely first. Model can sometimes fail to stop generation after providing correct answers.
53
-
54
  8. **Other Tips:**
55
  - Use simple instructions for instruction following.
56
  - For question answering and generation, follow the structure in the corresponding sample text.
@@ -96,12 +89,10 @@ st.title("SabiYarn-125M : Generates text in multiple Nigerian languages.")
96
 
97
  st.write("**Supported Languages: English, Yoruba, Igbo, Hausa, Pidgin, Efik, Urhobo, Fulfulde, Fulah. \nResults may not be coherent for less represented languages (i.e Efik, \
98
  Urhobo, Fulfulde, Fulah).**")
99
- st.write("**It takes a while (~25s) to return an output on the first 'generate' click. Avg response time: 1-2s
100
  st.write("**Model outputs 50 tokens as default. Adjust in the side bar.**")
101
  st.write("**For convenience, you can use chatgpt to provide input text and translate/evaluate model output.**")
102
  st.write("-" * 50)
103
-
104
-
105
  popular_topics = [
106
  "Sports", "Entertainment", "Politics", "Travel", "Technology",
107
  "Health", "Business", "Science", "Education", "Lifestyle",
@@ -109,14 +100,12 @@ popular_topics = [
109
  "History", "Law", "Literature", "Music", "News","Africa",
110
  "Philosophy", "Religion", "Society", "World"
111
  ]
112
-
113
  async def assign_topic(generated_text, topic_list=popular_topics):
114
  lower_generated_text = generated_text.lower()
115
  for topic in topic_list:
116
  if topic.lower() in lower_generated_text:
117
  return topic.title()
118
  return generated_text
119
-
120
 
121
  async def generate_from_api(user_input, generation_config):
122
  urls = [
@@ -124,7 +113,6 @@ async def generate_from_api(user_input, generation_config):
124
  "https://daveokpare--sabiyarn-fastapi-app.modal.run/predict",
125
  "https://damilojohn--sabiyarn-fastapi-app.modal.run/predict"
126
  ]
127
-
128
  payload = {
129
  "prompt": user_input,
130
  "config": generation_config
@@ -133,7 +121,6 @@ async def generate_from_api(user_input, generation_config):
133
  headers = {
134
  'Content-Type': 'application/json'
135
  }
136
-
137
  async with aiohttp.ClientSession() as session:
138
  for url in urls:
139
  try:
@@ -144,9 +131,7 @@ async def generate_from_api(user_input, generation_config):
144
  print(f"Failed to fetch from {url} with status code {response.status}")
145
  except Exception as e:
146
  print(f"Error fetching from {url}: {e}")
147
-
148
  return "FAILED"
149
-
150
  # Sample texts
151
  sample_texts = {
152
  "select":"",
@@ -174,7 +159,6 @@ sample_texts = {
174
  # "clean this text": "Abin mamaki ne aikin da shugabaZn HNajeriya ybake yi. kCiF 39gaba Tda haRkGa sir!",
175
  "headline of this text": '** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage,"'
176
  }
177
-
178
  instruction_wrap = {
179
  # "Translate 'Often, all Yoruba children...' to Yoruba":"<translate> Often, all Yoruba children take pride in speaking the Yoruba language. <yor>",
180
  "Me ya nuna?":"<prompt> Me ya nuna? <response>:",
@@ -190,14 +174,13 @@ instruction_wrap = {
190
  "Kai found one for sale online but it was too much money for her. Keeping the provided context in mind, please answer the subsequent question: What does Kai need to do before this? A. cheaper B. Open up her laptop C. save money":"<prompt> Kai found one for sale online but it was too much money for her. Keeping the provided context in mind, please answer the subsequent question: What does Kai need to do before this? A. cheaper B. Open up her laptop C. save money <response>:",
191
  "Speak Yoruba": "<prompt> Speak Yoruba <response>:",
192
  "Please narrate a short story in yoruba":"<prompt> Please narrate a short story in yoruba <response>:",
193
- "Afghanistan has around 150 radio stations and over 50 television stations, which includes the state-owned RTA TV and various private channels such as TOLO and Shamshad TV. The first Afghan newspaper was published in 1906 and there are hundreds of print outlets today. By the 1920s, Radio Kabul was broadcasting local radio services. Television programs began airing in the early 1970s. Voice of America, BBC, and Radio Free Europe/Radio Liberty (RFE/RL) broadcast in both of Afghanistan's official languages.\n Considering this context, what question would you ask?":"<prompt> Afghanistan has around 150 radio stations and over 50 television stations, which includes the state-owned RTA TV and various private channels such as TOLO and Shamshad TV. The first Afghan newspaper was published in 1906 and there are hundreds of print outlets today. By the 1920s, Radio Kabul was broadcasting local radio services. Television programs began airing in the early 1970s. Voice of America, BBC, and Radio Free Europe/Radio Liberty (RFE/RL) broadcast in both of Afghanistan's official languages.\n Considering this context, what question would you ask? <response>:"
194
  "Anyi na-echefu oke ike." : "<classify> Anyi na-echefu oke ike. <sentiment>",
195
  "Abin mamaki ne aikin da shugabaZn HNajeriya ybake yi. kCiF 39gaba Tda haRkGa sir!": "<clean> Abin mamaki ne aikin da shugabaZn HNajeriya ybake yi. kCiF 39gaba Tda haRkGa sir! <pcm>",
196
  "E sun, Alaga, fun ise amalayi ti e n se ni Naijiria. E maa ba a lo, egbon!": "<diacritize> E sun, Alaga, fun ise amalayi ti e n se ni Naijiria. E maa ba a lo, egbon! <yor>",
197
  "Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn": "<classify> Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn <topic>",
198
  '** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage,"': '<title> ** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage," <headline>',
199
  }
200
-
201
  # instruction_wrap = {
202
  # # "Translate 'Often, all Yoruba children...' to Yoruba":"<translate> Often, all Yoruba children take pride in speaking the Yoruba language. <yor>",
203
  # "Tell me a story in pidgin": "<prompt> Tell me a story in pidgin <response>:",
@@ -211,7 +194,6 @@ instruction_wrap = {
211
  # "what is the topic of this text": "<classify> Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn <topic>",
212
  # 'headline of this text': '<title> ** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage," <headline>',
213
  # }
214
-
215
  # Task options
216
  task_options = {
217
  "select": "{}",
@@ -226,7 +208,6 @@ task_options = {
226
  "Question-Answering" : "<prompt> {} <response>:",
227
  "Text Cleaning": "<clean> {} "
228
  }
229
-
230
  # Language options for diacritize, translation and clean tasks
231
  language_options = {
232
  "select": "",
@@ -239,38 +220,31 @@ language_options = {
239
  "Urhobo": "<urh>",
240
  "Fulah": "<ful>"
241
  }
242
-
243
 
244
  # Dropdown for sample text
245
  sample_text = st.selectbox("Select a sample text to test the model:", list(sample_texts.keys()))
246
-
247
  # Dropdown for tasks
248
  task = st.selectbox("Select a task for the model:", list(task_options.keys()))
249
-
250
  # Conditionally show language options dropdown for diacritize and clean tasks
251
  if task in ["Text Diacritization", "Text Cleaning", "Translation"]:
252
  language = st.selectbox("Select a Nigerian language:", list(language_options.keys()))
253
  task_value = f"{task_options[task]} {language_options[language]}"
254
  else:
255
  task_value = task_options[task]
256
-
257
  def wrap_text(text, task_value):
258
  tasks = ["<classify>", "<prompt>", "<clean>", "<title>", "<diacritize>", "<translate>"]
259
  if any(task in text for task in tasks):
260
  return text
261
  return task_value.format(text)
262
-
263
  # Text input
264
  user_input = st.text_area("Enter text below **(PLEASE, FIRST READ ALL INSTRUCTIONS IN THE SIDEBAR CAREFULLY FOR THE BEST EXPERIENCE)**: ", sample_texts.get(sample_text, sample_text))
265
-
266
  if task == "select":
267
  user_input = instruction_wrap.get(user_input, user_input)
268
 
269
  print("Final user input: ", user_input)
270
-
271
  if st.button("Generate"):
272
  if user_input:
273
- with st.spinner("Please wait..."):")
274
  wrapped_input = wrap_text(user_input, task_value)
275
  print("wrapped_input: ", wrapped_input)
276
  generation_config["max_new_tokens"]= min(max_new_tokens, 1024 - len(tokenizer.tokenize(wrapped_input)))
@@ -303,7 +277,6 @@ if st.button("Generate"):
303
  generated_text = generated_text[:15]
304
  print("split", generated_text.split(" ")[0], re.split(r"\.|\n|\*\*|\*", generated_text)[0], generated_text.split(" "))
305
  generated_text = re.split(r"\.|\n|\*\*|\*", generated_text)[0]
306
-
307
  generated_text = asyncio.run(assign_topic(generated_text))
308
 
309
  elif task == "Translation":
 
28
  st.sidebar.write("""
29
  1. **Write Text or Select Sample:**
30
  - Enter text in the text area or use the dropdown to choose a sample.
 
31
  2. **Select a Task:**
32
  - Choose a task from the **task dropdown** if using your own text.
33
  - **Important:** This ensures correct model response.
 
34
  3. **Avoid Conflicts:**
35
  - Don't select a sample text if using your own text.
 
36
  4. **Select Nigerian Language:**
37
  - If prompted, choose the Nigerian language (it represents the input/base language for diacritization/cleaning, target language for translation).
 
38
  5. **Generate Output:**
39
  - Click the Generate button.
 
40
  6. **Translation Tips:**
41
  - English as the target language gives the best results.
42
  - You can also test inter-language translation i.e yoruba to igbo
 
43
  7. **Performance Note:**
44
  - The model's performance varies due to its size and training data. It performs best on text generation and translation.
45
  - For other tasks, try multiple times if model's output is not optimal (This is due to the generator's sampling parameter settings).
46
  - It's best to read/understand/translate the model's output completely first. Model can sometimes fail to stop generation after providing correct answers.
 
47
  8. **Other Tips:**
48
  - Use simple instructions for instruction following.
49
  - For question answering and generation, follow the structure in the corresponding sample text.
 
89
 
90
  st.write("**Supported Languages: English, Yoruba, Igbo, Hausa, Pidgin, Efik, Urhobo, Fulfulde, Fulah. \nResults may not be coherent for less represented languages (i.e Efik, \
91
  Urhobo, Fulfulde, Fulah).**")
92
+ st.write("**It takes a while (~25s) to return an output on the first 'generate' click. Avg response time: 1-2s on GPU, 40s on CPU**")
93
  st.write("**Model outputs 50 tokens as default. Adjust in the side bar.**")
94
  st.write("**For convenience, you can use chatgpt to provide input text and translate/evaluate model output.**")
95
  st.write("-" * 50)
 
 
96
  popular_topics = [
97
  "Sports", "Entertainment", "Politics", "Travel", "Technology",
98
  "Health", "Business", "Science", "Education", "Lifestyle",
 
100
  "History", "Law", "Literature", "Music", "News","Africa",
101
  "Philosophy", "Religion", "Society", "World"
102
  ]
 
103
  async def assign_topic(generated_text, topic_list=popular_topics):
104
  lower_generated_text = generated_text.lower()
105
  for topic in topic_list:
106
  if topic.lower() in lower_generated_text:
107
  return topic.title()
108
  return generated_text
 
109
 
110
  async def generate_from_api(user_input, generation_config):
111
  urls = [
 
113
  "https://daveokpare--sabiyarn-fastapi-app.modal.run/predict",
114
  "https://damilojohn--sabiyarn-fastapi-app.modal.run/predict"
115
  ]
 
116
  payload = {
117
  "prompt": user_input,
118
  "config": generation_config
 
121
  headers = {
122
  'Content-Type': 'application/json'
123
  }
 
124
  async with aiohttp.ClientSession() as session:
125
  for url in urls:
126
  try:
 
131
  print(f"Failed to fetch from {url} with status code {response.status}")
132
  except Exception as e:
133
  print(f"Error fetching from {url}: {e}")
 
134
  return "FAILED"
 
135
  # Sample texts
136
  sample_texts = {
137
  "select":"",
 
159
  # "clean this text": "Abin mamaki ne aikin da shugabaZn HNajeriya ybake yi. kCiF 39gaba Tda haRkGa sir!",
160
  "headline of this text": '** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage,"'
161
  }
 
162
  instruction_wrap = {
163
  # "Translate 'Often, all Yoruba children...' to Yoruba":"<translate> Often, all Yoruba children take pride in speaking the Yoruba language. <yor>",
164
  "Me ya nuna?":"<prompt> Me ya nuna? <response>:",
 
174
  "Kai found one for sale online but it was too much money for her. Keeping the provided context in mind, please answer the subsequent question: What does Kai need to do before this? A. cheaper B. Open up her laptop C. save money":"<prompt> Kai found one for sale online but it was too much money for her. Keeping the provided context in mind, please answer the subsequent question: What does Kai need to do before this? A. cheaper B. Open up her laptop C. save money <response>:",
175
  "Speak Yoruba": "<prompt> Speak Yoruba <response>:",
176
  "Please narrate a short story in yoruba":"<prompt> Please narrate a short story in yoruba <response>:",
177
+ "Afghanistan has around 150 radio stations and over 50 television stations, which includes the state-owned RTA TV and various private channels such as TOLO and Shamshad TV. The first Afghan newspaper was published in 1906 and there are hundreds of print outlets today. By the 1920s, Radio Kabul was broadcasting local radio services. Television programs began airing in the early 1970s. Voice of America, BBC, and Radio Free Europe/Radio Liberty (RFE/RL) broadcast in both of Afghanistan's official languages.\n Considering this context, what question would you ask?":"<prompt> Afghanistan has around 150 radio stations and over 50 television stations, which includes the state-owned RTA TV and various private channels such as TOLO and Shamshad TV. The first Afghan newspaper was published in 1906 and there are hundreds of print outlets today. By the 1920s, Radio Kabul was broadcasting local radio services. Television programs began airing in the early 1970s. Voice of America, BBC, and Radio Free Europe/Radio Liberty (RFE/RL) broadcast in both of Afghanistan's official languages.\n Considering this context, what question would you ask? <response>:",
178
  "Anyi na-echefu oke ike." : "<classify> Anyi na-echefu oke ike. <sentiment>",
179
  "Abin mamaki ne aikin da shugabaZn HNajeriya ybake yi. kCiF 39gaba Tda haRkGa sir!": "<clean> Abin mamaki ne aikin da shugabaZn HNajeriya ybake yi. kCiF 39gaba Tda haRkGa sir! <pcm>",
180
  "E sun, Alaga, fun ise amalayi ti e n se ni Naijiria. E maa ba a lo, egbon!": "<diacritize> E sun, Alaga, fun ise amalayi ti e n se ni Naijiria. E maa ba a lo, egbon! <yor>",
181
  "Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn": "<classify> Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn <topic>",
182
  '** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage,"': '<title> ** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage," <headline>',
183
  }
 
184
  # instruction_wrap = {
185
  # # "Translate 'Often, all Yoruba children...' to Yoruba":"<translate> Often, all Yoruba children take pride in speaking the Yoruba language. <yor>",
186
  # "Tell me a story in pidgin": "<prompt> Tell me a story in pidgin <response>:",
 
194
  # "what is the topic of this text": "<classify> Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn <topic>",
195
  # 'headline of this text': '<title> ** Sylvain Itté French ambassador don comot Niger Republic **. Sylvain Itté, di French ambassador for Niger don comot Niamey and currently e dey for flight from Ndjamena to Paris. Sylvain Itté, di French ambassador for Niger don comot Niamey very early dis morning and currently e dey for flight from Ndjamena to Paris.\n\nDi military detain Bazoum and im family for di presidential palace. Niger na former French colony, and France still get 1,500 sojas for di African country.\n\n"France don decide to withdraw dia ambassador. In di next hours our ambassador and several diplomats go return to France," Oga Macron tok.\n\nE add say di military co-operation dey "over" and French troops go leave in "di months to come".\n\n"Dis Sunday we celebrate one new step towards di sovereignty of Niger," di junta tok, for one statement wey AFP news agency quote.\n\nDi decision by Paris dey come afta months of hostility and protest against di presence of French for di kontri, wit regular demonstrations for di capital Niamey.\n\nDi move don scata France operations against Islamist militants for di wider Sahel region and Paris influence for there. But oga Macron tok say "putschists no go hold France hostage," <headline>',
196
  # }
 
197
  # Task options
198
  task_options = {
199
  "select": "{}",
 
208
  "Question-Answering" : "<prompt> {} <response>:",
209
  "Text Cleaning": "<clean> {} "
210
  }
 
211
  # Language options for diacritize, translation and clean tasks
212
  language_options = {
213
  "select": "",
 
220
  "Urhobo": "<urh>",
221
  "Fulah": "<ful>"
222
  }
 
223
 
224
  # Dropdown for sample text
225
  sample_text = st.selectbox("Select a sample text to test the model:", list(sample_texts.keys()))
 
226
  # Dropdown for tasks
227
  task = st.selectbox("Select a task for the model:", list(task_options.keys()))
 
228
  # Conditionally show language options dropdown for diacritize and clean tasks
229
  if task in ["Text Diacritization", "Text Cleaning", "Translation"]:
230
  language = st.selectbox("Select a Nigerian language:", list(language_options.keys()))
231
  task_value = f"{task_options[task]} {language_options[language]}"
232
  else:
233
  task_value = task_options[task]
 
234
  def wrap_text(text, task_value):
235
  tasks = ["<classify>", "<prompt>", "<clean>", "<title>", "<diacritize>", "<translate>"]
236
  if any(task in text for task in tasks):
237
  return text
238
  return task_value.format(text)
 
239
  # Text input
240
  user_input = st.text_area("Enter text below **(PLEASE, FIRST READ ALL INSTRUCTIONS IN THE SIDEBAR CAREFULLY FOR THE BEST EXPERIENCE)**: ", sample_texts.get(sample_text, sample_text))
 
241
  if task == "select":
242
  user_input = instruction_wrap.get(user_input, user_input)
243
 
244
  print("Final user input: ", user_input)
 
245
  if st.button("Generate"):
246
  if user_input:
247
+ with st.spinner("Please wait..."):
248
  wrapped_input = wrap_text(user_input, task_value)
249
  print("wrapped_input: ", wrapped_input)
250
  generation_config["max_new_tokens"]= min(max_new_tokens, 1024 - len(tokenizer.tokenize(wrapped_input)))
 
277
  generated_text = generated_text[:15]
278
  print("split", generated_text.split(" ")[0], re.split(r"\.|\n|\*\*|\*", generated_text)[0], generated_text.split(" "))
279
  generated_text = re.split(r"\.|\n|\*\*|\*", generated_text)[0]
 
280
  generated_text = asyncio.run(assign_topic(generated_text))
281
 
282
  elif task == "Translation":