Spaces:
Sleeping
Sleeping
add stats_text
Browse files- app.py +10 -2
- functions/__init__.py +1 -0
- functions/text_stats.py +12 -0
- templates/index.html +2 -2
app.py
CHANGED
|
@@ -8,7 +8,8 @@ from functions import (
|
|
| 8 |
sentiment_analysis,
|
| 9 |
generate_text,
|
| 10 |
summarize_text,
|
| 11 |
-
chat_with_agent
|
|
|
|
| 12 |
)
|
| 13 |
|
| 14 |
|
|
@@ -23,7 +24,6 @@ app.secret_key = os.getenv("SECRET_KEY", os.urandom(24))
|
|
| 23 |
@app.route('/', methods = ['GET', 'POST'])
|
| 24 |
def index():
|
| 25 |
result_text = None
|
| 26 |
-
result_image = None
|
| 27 |
error = None
|
| 28 |
chat_history = session.get('chat_history', [])
|
| 29 |
|
|
@@ -54,6 +54,14 @@ def index():
|
|
| 54 |
elif action=="chat":
|
| 55 |
pass
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
return render_template('index.html',
|
| 58 |
result_text=result_text,
|
| 59 |
error=error,
|
|
|
|
| 8 |
sentiment_analysis,
|
| 9 |
generate_text,
|
| 10 |
summarize_text,
|
| 11 |
+
chat_with_agent,
|
| 12 |
+
text_stats
|
| 13 |
)
|
| 14 |
|
| 15 |
|
|
|
|
| 24 |
@app.route('/', methods = ['GET', 'POST'])
|
| 25 |
def index():
|
| 26 |
result_text = None
|
|
|
|
| 27 |
error = None
|
| 28 |
chat_history = session.get('chat_history', [])
|
| 29 |
|
|
|
|
| 54 |
elif action=="chat":
|
| 55 |
pass
|
| 56 |
|
| 57 |
+
elif action =="stats":
|
| 58 |
+
text=request.get('text','')
|
| 59 |
+
if text:
|
| 60 |
+
result_text = text_stats(text)
|
| 61 |
+
else:
|
| 62 |
+
error="Введите текст"
|
| 63 |
+
|
| 64 |
+
|
| 65 |
return render_template('index.html',
|
| 66 |
result_text=result_text,
|
| 67 |
error=error,
|
functions/__init__.py
CHANGED
|
@@ -2,3 +2,4 @@ from functions.sentiment import sentiment_analysis
|
|
| 2 |
from functions.generate_text import generate_text
|
| 3 |
from functions.summarize import summarize_text
|
| 4 |
from functions.chat import chat_with_agent
|
|
|
|
|
|
| 2 |
from functions.generate_text import generate_text
|
| 3 |
from functions.summarize import summarize_text
|
| 4 |
from functions.chat import chat_with_agent
|
| 5 |
+
from functions.text_stats import text_stats
|
functions/text_stats.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
def text_stats(text:str)->str:
|
| 4 |
+
if not text:
|
| 5 |
+
return "Текст пуст"
|
| 6 |
+
char_count=len(text)
|
| 7 |
+
char_no_space=len(text.replace(' ', ''))
|
| 8 |
+
word_count=len(text.split())
|
| 9 |
+
|
| 10 |
+
return(f"Символов (с пробелами): {char_count}"
|
| 11 |
+
f"Символов (без пробелов): {char_no_space}"
|
| 12 |
+
f"Слов: {word_count}")
|
templates/index.html
CHANGED
|
@@ -249,7 +249,7 @@
|
|
| 249 |
<body>
|
| 250 |
<div class="container">
|
| 251 |
<h1>НейроЛингвист</h1>
|
| 252 |
-
<div class="subhead">
|
| 253 |
|
| 254 |
{% if error %}
|
| 255 |
<div class="error">{{ error }}</div>
|
|
@@ -263,6 +263,7 @@
|
|
| 263 |
<option value="generate">Генерация</option>
|
| 264 |
<option value="summarize">Пересказ</option>
|
| 265 |
<option value="chat">Чат</option>
|
|
|
|
| 266 |
</select>
|
| 267 |
<br>
|
| 268 |
|
|
@@ -291,7 +292,6 @@
|
|
| 291 |
</div>
|
| 292 |
|
| 293 |
<script>
|
| 294 |
-
// Тот же JS, что был ранее (без изменений)
|
| 295 |
const initialHistory = {{ chat_history|tojson|safe }};
|
| 296 |
const chatContainer = document.getElementById('chat-container');
|
| 297 |
const textArea = document.getElementById('text-input-area');
|
|
|
|
| 249 |
<body>
|
| 250 |
<div class="container">
|
| 251 |
<h1>НейроЛингвист</h1>
|
| 252 |
+
<div class="subhead">Текстовые функции + чат с ИИ</div>
|
| 253 |
|
| 254 |
{% if error %}
|
| 255 |
<div class="error">{{ error }}</div>
|
|
|
|
| 263 |
<option value="generate">Генерация</option>
|
| 264 |
<option value="summarize">Пересказ</option>
|
| 265 |
<option value="chat">Чат</option>
|
| 266 |
+
<option value="stats">Статистика текста</option>
|
| 267 |
</select>
|
| 268 |
<br>
|
| 269 |
|
|
|
|
| 292 |
</div>
|
| 293 |
|
| 294 |
<script>
|
|
|
|
| 295 |
const initialHistory = {{ chat_history|tojson|safe }};
|
| 296 |
const chatContainer = document.getElementById('chat-container');
|
| 297 |
const textArea = document.getElementById('text-input-area');
|