Spaces:
Sleeping
Sleeping
added summary prompt
Browse files
app.py
CHANGED
|
@@ -15,6 +15,25 @@ def format_prompt(message, history):
|
|
| 15 |
prompt += f"[INST] {message} [/INST]"
|
| 16 |
return prompt
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def generate(
|
| 19 |
prompt, history=[], temperature=0, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.0,
|
| 20 |
):
|
|
@@ -61,11 +80,14 @@ def completion_route():
|
|
| 61 |
def getsummary_route():
|
| 62 |
data = request.get_json()
|
| 63 |
text = data.get('text', '')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
response = generate(summary_prompt[:52000])
|
| 67 |
-
|
| 68 |
-
return jsonify({'result': response})
|
| 69 |
|
| 70 |
@app.route('/cleantext', methods=['POST'])
|
| 71 |
def cleantext_route():
|
|
|
|
| 15 |
prompt += f"[INST] {message} [/INST]"
|
| 16 |
return prompt
|
| 17 |
|
| 18 |
+
def split_text(text):
|
| 19 |
+
max_chars = 3500
|
| 20 |
+
sentences = text.split('.')
|
| 21 |
+
lines = []
|
| 22 |
+
for sentence in sentences:
|
| 23 |
+
lines.extend(sentence.split('\n'))
|
| 24 |
+
|
| 25 |
+
result = []
|
| 26 |
+
current_chunk = ''
|
| 27 |
+
for line in lines:
|
| 28 |
+
if len(current_chunk) + len(line) < max_chars:
|
| 29 |
+
current_chunk += line + '.'
|
| 30 |
+
else:
|
| 31 |
+
result.append(current_chunk.strip())
|
| 32 |
+
current_chunk = line + '.'
|
| 33 |
+
if current_chunk:
|
| 34 |
+
result.append(current_chunk.strip())
|
| 35 |
+
return result
|
| 36 |
+
|
| 37 |
def generate(
|
| 38 |
prompt, history=[], temperature=0, max_new_tokens=2000, top_p=0.95, repetition_penalty=1.0,
|
| 39 |
):
|
|
|
|
| 80 |
def getsummary_route():
|
| 81 |
data = request.get_json()
|
| 82 |
text = data.get('text', '')
|
| 83 |
+
pages = split_text(text)
|
| 84 |
+
result = ''
|
| 85 |
+
for page in pages:
|
| 86 |
+
summary_prompt = f'''<s>[INST]выпиши из текста в виде трех списков 1.какие вопросы, темы обсуждались, 2. какие проблемы были озвучены 3. какие предложения были сформулированы: {page}[/INST]'''
|
| 87 |
+
response = generate(summary_prompt[:52000])
|
| 88 |
+
result = result + '\n'+response
|
| 89 |
|
| 90 |
+
return jsonify({'result': result})
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
@app.route('/cleantext', methods=['POST'])
|
| 93 |
def cleantext_route():
|