BeardedMonster commited on
Commit
ea3de3e
·
verified ·
1 Parent(s): 75f32e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -100,12 +100,21 @@ popular_topics = [
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 = [
@@ -238,7 +247,7 @@ def wrap_text(text, task_value):
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
- n_sentences = len(re.split(r"\.|\n", user_input))
242
 
243
  if task == "select":
244
  user_input = instruction_wrap.get(user_input, user_input)
 
100
  "History", "Law", "Literature", "Music", "News","Africa",
101
  "Philosophy", "Religion", "Society", "World"
102
  ]
103
+
104
  async def assign_topic(generated_text, topic_list=popular_topics):
105
  lower_generated_text = generated_text.lower()
106
  for topic in topic_list:
107
  if topic.lower() in lower_generated_text:
108
  return topic.title()
109
  return generated_text
110
+
111
+ def count_sentences(text):
112
+ # Split the text based on sentence-ending punctuation followed by a space or end of string
113
+ sentences = re.split(r'[.!?]+\s*', text.strip())
114
+ # Filter out any empty strings from the resulting list
115
+ sentences = [sentence for sentence in sentences if sentence]
116
+ return len(sentences)
117
+
118
 
119
  async def generate_from_api(user_input, generation_config):
120
  urls = [
 
247
  return task_value.format(text)
248
  # Text input
249
  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))
250
+ n_sentences = count_sentences(user_input)
251
 
252
  if task == "select":
253
  user_input = instruction_wrap.get(user_input, user_input)