GuysTrans commited on
Commit
c96eef2
1 Parent(s): db16679

Update post-process response

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -2,6 +2,7 @@ from flask import Flask, request
2
  import requests
3
  import os
4
  import re
 
5
  from transformers import AutoModelForSeq2SeqLM
6
  from transformers import AutoTokenizer
7
  from langdetect import detect
@@ -24,7 +25,6 @@ map_words = {
24
  }
25
 
26
  word_remove_sentence = [
27
- "welcome to",
28
  "hello",
29
  "hi",
30
  "regards",
@@ -139,24 +139,21 @@ def chat():
139
  return {"message": response}
140
 
141
  def post_process(output):
142
- output = str(output)
 
143
  lines = output.split("\n")
144
  for line in lines:
145
  for word in word_remove_sentence:
146
- if string_found(word, line.lower()):
147
  lines.remove(line)
148
  break
149
 
150
  output = "\n".join(lines)
151
  for item in map_words.keys():
152
  output = re.sub(item, map_words[item], output, re.I)
153
-
154
- return output.strip()
155
-
156
- def string_found(string1, string2):
157
- if re.search(r"\b" + re.escape(string1) + r"\b", string2):
158
- return True
159
- return False
160
 
161
 
162
  subprocess.Popen(["autossh", "-M", "0", "-tt", "-o", "StrictHostKeyChecking=no",
 
2
  import requests
3
  import os
4
  import re
5
+ import textwrap
6
  from transformers import AutoModelForSeq2SeqLM
7
  from transformers import AutoTokenizer
8
  from langdetect import detect
 
25
  }
26
 
27
  word_remove_sentence = [
 
28
  "hello",
29
  "hi",
30
  "regards",
 
139
  return {"message": response}
140
 
141
  def post_process(output):
142
+
143
+ output = textwrap.fill(textwrap.dedent(output).strip(), width=120)
144
  lines = output.split("\n")
145
  for line in lines:
146
  for word in word_remove_sentence:
147
+ if word in line.lower():
148
  lines.remove(line)
149
  break
150
 
151
  output = "\n".join(lines)
152
  for item in map_words.keys():
153
  output = re.sub(item, map_words[item], output, re.I)
154
+
155
+ return textwrap.fill(textwrap.dedent(output).strip(), width=120)
156
+
 
 
 
 
157
 
158
 
159
  subprocess.Popen(["autossh", "-M", "0", "-tt", "-o", "StrictHostKeyChecking=no",