BeardedMonster commited on
Commit
1cd1646
·
verified ·
1 Parent(s): 15cce89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -12,11 +12,11 @@ tokenizer = AutoTokenizer.from_pretrained(repo_name, trust_remote_code=True)
12
  # Add sidebar with instructions
13
  st.sidebar.title("Instructions: How to use")
14
  st.sidebar.write("""
15
- 1. Write something in the text area (a prompt or random text).
16
- 2. Select a task from the dropdown menu below.
17
  3. If a dropdown menu pops up for a nigerian language, select the target nigerian language.
18
  4. Click Generate to get a response below the text area.
19
- **Note: Model's performance vary with prompts due to model size and training data distribution.**\n
20
  5. Lastly, you can play with some of the generation parameters below to improve performance.
21
  """)
22
 
@@ -77,8 +77,8 @@ sample_texts = {
77
  "Translate 'how are you?' to Yoruba": "Translate 'how are you?' to Yoruba",
78
  "Classify the sentiment": "Anyi na-echefu oke ike.",
79
  "what is the topic of this text": "Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn",
80
- "diacritize this text: ": "",
81
- "clean this text": ""
82
  "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,"'
83
  }
84
 
@@ -114,6 +114,7 @@ language_options = {
114
  "Fulah": "<ful>"
115
  }
116
 
 
117
  # Dropdown for sample text
118
  sample_text = st.selectbox("Select a sample text to test the model:", list(sample_texts.keys()))
119
 
@@ -127,6 +128,13 @@ if task in ["Diacritize text", "Clean text"]:
127
  else:
128
  task_value = task_options[task]
129
 
 
 
 
 
 
 
 
130
  # Text input
131
  user_input = st.text_area("Enter text below **(please, first read the instructions on how to use in the side bar for better experience)**: ", instruction_wrap.get(sample_texts[sample_text], sample_texts[sample_text]))
132
 
@@ -134,7 +142,7 @@ if st.button("Generate"):
134
  if user_input:
135
  try:
136
  st.write("**Generated Text Below:**")
137
- wrapped_input = task_value.format(user_input)
138
  print("wrapped_input: ", wrapped_input)
139
  generation_config["max_new_tokens"]= min(max_new_tokens, 1024 - len(tokenizer.tokenize(wrapped_input)))
140
  generated_text = asyncio.run(generate_from_api(wrapped_input, generation_config))
 
12
  # Add sidebar with instructions
13
  st.sidebar.title("Instructions: How to use")
14
  st.sidebar.write("""
15
+ 1. Write something in the text area (a prompt or random text) or use the dropdown menu to select predefined text.
16
+ 2. Select a task from the task dropdown menu below.
17
  3. If a dropdown menu pops up for a nigerian language, select the target nigerian language.
18
  4. Click Generate to get a response below the text area.
19
+ **Note: Model's performance when given prompts vary due to model size and training data distribution.**\n
20
  5. Lastly, you can play with some of the generation parameters below to improve performance.
21
  """)
22
 
 
77
  "Translate 'how are you?' to Yoruba": "Translate 'how are you?' to Yoruba",
78
  "Classify the sentiment": "Anyi na-echefu oke ike.",
79
  "what is the topic of this text": "Africa Free Trade Zone: Kò sí ìdènà láti kó ọjà láti orílẹ̀èdè kan sí òmíràn",
80
+ "diacritize this text: ": "E sun, Alaga, fun ise amalayi ti e n se ni Naijiria. E maa ba a lo, egbon!",
81
+ "clean this text": "Di service say sheVbin doE tlykto find out how Zelensky wak^ g3 be before im go visit MykolailXwey flood fKg Junew Zele?sky confam s,y rem don inform a2 abouo di frrest, im sHy dR_head of SBU bin don update aI abou.Wdi "fiMht againsX traitorsfLZelevsky bin visi# Mykolaiv for June tk see di dam&ge wey di collapse of KakhoYka dam "ause Rgd den im v:sit again for July afta Russia1heavy bo+bing. Di 8ecurity sBrviceTs1y dem bin know/Mbout di plan bev9re di ;isit, snd dat onG make put vdditional security measurZs{",
82
  "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,"'
83
  }
84
 
 
114
  "Fulah": "<ful>"
115
  }
116
 
117
+
118
  # Dropdown for sample text
119
  sample_text = st.selectbox("Select a sample text to test the model:", list(sample_texts.keys()))
120
 
 
128
  else:
129
  task_value = task_options[task]
130
 
131
+ def wrap_text(text, task_value):
132
+ tasks = ["<classify>", "<prompt>", "<clean>", "<title>", "<diacritize>"]
133
+ if any(task in text for task in tasks):
134
+ return text
135
+ return task_value.format(text)
136
+
137
+
138
  # Text input
139
  user_input = st.text_area("Enter text below **(please, first read the instructions on how to use in the side bar for better experience)**: ", instruction_wrap.get(sample_texts[sample_text], sample_texts[sample_text]))
140
 
 
142
  if user_input:
143
  try:
144
  st.write("**Generated Text Below:**")
145
+ wrapped_input = wrap_text(user_input)
146
  print("wrapped_input: ", wrapped_input)
147
  generation_config["max_new_tokens"]= min(max_new_tokens, 1024 - len(tokenizer.tokenize(wrapped_input)))
148
  generated_text = asyncio.run(generate_from_api(wrapped_input, generation_config))