BeardedMonster commited on
Commit
7e4e637
·
verified ·
1 Parent(s): cf6f089

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -107,6 +107,22 @@ st.write("**For convenience, you can use chatgpt to copy text and translate/eval
107
  st.write("-" * 50)
108
 
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  async def generate_from_api(user_input, generation_config):
111
  urls = [
112
  "https://pauljeffrey--sabiyarn-fastapi-app.modal.run/predict",
@@ -148,6 +164,7 @@ sample_texts = {
148
  "who are you?": "who are you?",
149
  "Speak Yoruba": "Speak Yoruba",
150
  "Translate 'how are you?' to Yoruba": "how are you?",
 
151
  "Translate 'Often, all Yoruba children...' to Yoruba": "Often, all Yoruba children take pride in speaking the Yoruba language.",
152
  "Classify the sentiment": "Anyi na-echefu oke ike.",
153
  "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",
@@ -159,6 +176,7 @@ sample_texts = {
159
  instruction_wrap = {
160
  # "Translate 'Often, all Yoruba children...' to Yoruba":"<translate> Often, all Yoruba children take pride in speaking the Yoruba language. <yor>",
161
  "Tell me a story in pidgin": "<prompt> Tell me a story in pidgin <response>:",
 
162
  "how are you?": "<translate> how are you? <yor>:",
163
  "Often, all Yoruba children take pride in speaking the Yoruba language.": "<translate> Often, all Yoruba children take pride in speaking the Yoruba language. <yor>",
164
  "who are you?": "<prompt> who are you? <response>:",
@@ -271,6 +289,8 @@ if st.button("Generate"):
271
  generated_text = generated_text[:15]
272
  print("split", generated_text.split(" ")[0], re.split(r"\.|\n|\*\*|\*", generated_text)[0], generated_text.split(" "))
273
  generated_text = re.split(r"\.|\n|\*\*|\*", generated_text)[0]
 
 
274
 
275
  elif task == "Translation":
276
  n_sentences = len(user_input.split("."))
 
107
  st.write("-" * 50)
108
 
109
 
110
+ popular_topics = [
111
+ "Sports", "Entertainment", "Politics", "Travel", "Technology",
112
+ "Health", "Business", "Science", "Education", "Lifestyle",
113
+ "Culture", "Environment", "Finance", "Food", "Gaming",
114
+ "History", "Law", "Literature", "Music", "News",
115
+ "Philosophy", "Religion", "Society", "World"
116
+ ]
117
+
118
+ async def assign_topic(generated_text, topic_list=popular_topics):
119
+ lower_generated_text = generated_text.lower()
120
+ for topic in topic_list:
121
+ if topic.lower() in lower_generated_text:
122
+ return topic.title()
123
+ return generated_text
124
+
125
+
126
  async def generate_from_api(user_input, generation_config):
127
  urls = [
128
  "https://pauljeffrey--sabiyarn-fastapi-app.modal.run/predict",
 
164
  "who are you?": "who are you?",
165
  "Speak Yoruba": "Speak Yoruba",
166
  "Translate 'how are you?' to Yoruba": "how are you?",
167
+ "Translate to pidgin": "Spain won the 2024 europa football cup. it was a tough one because they had to play very strong opponents in the quarter-finals, semi-finals and finals.",
168
  "Translate 'Often, all Yoruba children...' to Yoruba": "Often, all Yoruba children take pride in speaking the Yoruba language.",
169
  "Classify the sentiment": "Anyi na-echefu oke ike.",
170
  "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",
 
176
  instruction_wrap = {
177
  # "Translate 'Often, all Yoruba children...' to Yoruba":"<translate> Often, all Yoruba children take pride in speaking the Yoruba language. <yor>",
178
  "Tell me a story in pidgin": "<prompt> Tell me a story in pidgin <response>:",
179
+ "Spain won the 2024 europa football cup. it was a tough one because they had to play very strong opponents in the quarter-finals, semi-finals and finals.": "<translate> Spain won the 2024 europa football cup. it was a tough one because they had to play very strong opponents in the quarter-finals, semi-finals and finals. <pcm>"
180
  "how are you?": "<translate> how are you? <yor>:",
181
  "Often, all Yoruba children take pride in speaking the Yoruba language.": "<translate> Often, all Yoruba children take pride in speaking the Yoruba language. <yor>",
182
  "who are you?": "<prompt> who are you? <response>:",
 
289
  generated_text = generated_text[:15]
290
  print("split", generated_text.split(" ")[0], re.split(r"\.|\n|\*\*|\*", generated_text)[0], generated_text.split(" "))
291
  generated_text = re.split(r"\.|\n|\*\*|\*", generated_text)[0]
292
+
293
+ generated_text = asyncio.run(assign_topic(generated_text))
294
 
295
  elif task == "Translation":
296
  n_sentences = len(user_input.split("."))